1
- name : Build and Release Import Script
1
+ name : Build and Release Astro Import Script
2
2
3
3
on :
4
4
push :
@@ -13,19 +13,35 @@ jobs:
13
13
name : Build
14
14
runs-on : ubuntu-latest
15
15
timeout-minutes : 5
16
+ strategy :
17
+ matrix :
18
+ goos : [ linux, windows, darwin ]
19
+ goarch : [ amd64, arm64 ]
16
20
steps :
17
21
- uses : actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
18
22
- uses : actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
19
23
with :
20
24
go-version-file : ' go.mod'
21
25
cache : true
22
26
- 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
25
41
uses : actions/upload-artifact@v3
26
42
with :
27
- name : terraform-import-script
28
- path : terraform-import-script
43
+ name : binaries
44
+ path : terraform-provider-astro- import-script_*
29
45
30
46
lint :
31
47
name : Lint
@@ -40,30 +56,55 @@ jobs:
40
56
- run : go vet ./import/import_script.go
41
57
- run : make validate-fmt
42
58
43
- goreleaser :
59
+ release :
60
+ name : Create Release
44
61
needs : [build, lint]
45
62
runs-on : ubuntu-latest
46
63
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
60
69
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
62
79
env :
63
80
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
64
- GPG_FINGERPRINT : ${{ steps.import_gpg.outputs.fingerprint }}
65
- - name : Upload GoReleaser artifacts
66
- uses : actions/upload-artifact@v3
67
81
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
+ }
0 commit comments