Skip to content

Commit bf6a998

Browse files
authored
Fix import script github action (#136)
1 parent b5b5f97 commit bf6a998

File tree

2 files changed

+66
-83
lines changed

2 files changed

+66
-83
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and Release Import Script
1+
name: Build and Release Astro Import Script
22

33
on:
44
push:
@@ -13,19 +13,35 @@ jobs:
1313
name: Build
1414
runs-on: ubuntu-latest
1515
timeout-minutes: 5
16+
strategy:
17+
matrix:
18+
goos: [ linux, windows, darwin ]
19+
goarch: [ amd64, arm64 ]
1620
steps:
1721
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
1822
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
1923
with:
2024
go-version-file: 'go.mod'
2125
cache: true
2226
- run: go mod download
23-
- run: go build -v -o terraform-import-script ./import/import_script.go
24-
- name: Upload Terraform import script artifact
27+
- name: Get version
28+
id: get_version
29+
run: echo "VERSION=${GITHUB_REF#refs/tags/import/}" >> $GITHUB_OUTPUT
30+
- name: Build
31+
env:
32+
GOOS: ${{ matrix.goos }}
33+
GOARCH: ${{ matrix.goarch }}
34+
run: |
35+
output_name="terraform-provider-astro-import-script_${{ steps.get_version.outputs.VERSION }}_${{ matrix.goos }}_${{ matrix.goarch }}"
36+
if [ "${{ matrix.goos }}" = "windows" ]; then
37+
output_name="${output_name}.exe"
38+
fi
39+
go build -o "${output_name}" ./import/import_script.go
40+
- name: Upload artifact
2541
uses: actions/upload-artifact@v3
2642
with:
27-
name: terraform-import-script
28-
path: terraform-import-script
43+
name: binaries
44+
path: terraform-provider-astro-import-script_*
2945

3046
lint:
3147
name: Lint
@@ -40,30 +56,55 @@ jobs:
4056
- run: go vet ./import/import_script.go
4157
- run: make validate-fmt
4258

43-
goreleaser:
59+
release:
60+
name: Create Release
4461
needs: [build, lint]
4562
runs-on: ubuntu-latest
4663
steps:
47-
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
48-
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
49-
with:
50-
go-version-file: 'go.mod'
51-
cache: true
52-
- name: Import GPG key
53-
uses: crazy-max/ghaction-import-gpg@v5
54-
id: import_gpg
55-
with:
56-
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
57-
passphrase: ${{ secrets.PASSPHRASE }}
58-
- name: Run GoReleaser
59-
uses: goreleaser/goreleaser-action@5742e2a039330cbb23ebf35f046f814d4c6ff811 # v5.1.0
64+
- name: Checkout code
65+
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
66+
67+
- name: Download artifacts
68+
uses: actions/download-artifact@v3
6069
with:
61-
args: release --clean --config .goreleaser.import.yml
70+
name: binaries
71+
72+
- name: Get the version
73+
id: get_version
74+
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
75+
76+
- name: Create Release
77+
id: create_release
78+
uses: actions/create-release@v1
6279
env:
6380
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64-
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
65-
- name: Upload GoReleaser artifacts
66-
uses: actions/upload-artifact@v3
6781
with:
68-
name: goreleaser-artifacts
69-
path: dist/*
82+
tag_name: ${{ steps.get_version.outputs.VERSION }}
83+
release_name: Release ${{ steps.get_version.outputs.VERSION }}
84+
draft: false
85+
prerelease: false
86+
87+
- name: Upload Release Assets
88+
uses: actions/github-script@v7
89+
with:
90+
github-token: ${{ secrets.GITHUB_TOKEN }}
91+
script: |
92+
const fs = require('fs').promises;
93+
const { repo: { owner, repo }, sha } = context;
94+
const release = await github.rest.repos.getReleaseByTag({
95+
owner,
96+
repo,
97+
tag: '${{ steps.get_version.outputs.VERSION }}'
98+
});
99+
const files = await fs.readdir('.');
100+
for (const file of files) {
101+
if (file.startsWith('terraform-provider-astro-import-script_')) {
102+
await github.rest.repos.uploadReleaseAsset({
103+
owner,
104+
repo,
105+
release_id: release.data.id,
106+
name: file,
107+
data: await fs.readFile(file)
108+
});
109+
}
110+
}

.goreleaser.import.yml

-58
This file was deleted.

0 commit comments

Comments
 (0)