-
-
Notifications
You must be signed in to change notification settings - Fork 23
124 lines (122 loc) · 4.86 KB
/
releases.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
name: Release
on:
push:
tags:
- "v*"
jobs:
release:
name: Create Release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
id: ${{steps.create_release.outputs.id}}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set env RELEASE_VERSION
run: echo "RELEASE_VERSION=$(echo ${GITHUB_REF} | cut -d'/' -f3)" >> $GITHUB_ENV
- name: Create Release
id: create_release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.RELEASE_TOKEN }}
name: ${{ env.RELEASE_VERSION }}
omitBody: true
draft: true
prerelease: false
assets:
name: Push assets for ${{ matrix.goos }}/${{ matrix.goarch }}
needs: release
runs-on: ubuntu-latest
strategy:
matrix:
# build and publish in parallel multiple OS/ARCH
goos: [linux, windows, darwin, freebsd]
goarch: [amd64, arm64]
exclude:
- goos: windows
goarch: arm64
steps:
- name: Set up Go 1.23
uses: actions/setup-go@v5
with:
go-version: '1.23'
check-latest: true
id: go
- name: Show version
run: go version
- name: Check out code
uses: actions/checkout@v4
- name: Set env
run: |
echo "CGO_ENABLED=0" >> $GITHUB_ENV
echo "RELEASE_VERSION=$(echo ${GITHUB_REF} | cut -d'/' -f3 | sed 's/^v//')" >> $GITHUB_ENV
echo "REPO_NAME=$(echo ${GITHUB_REPOSITORY} | cut -d'/' -f2)" >> $GITHUB_ENV
echo "GOOS=$(echo ${{ matrix.goos }})" >> $GITHUB_ENV
echo "GOARCH=$(echo ${{ matrix.goarch }})" >> $GITHUB_ENV
- name: Define version in build
run: echo ${RELEASE_VERSION} > internal/version/version.txt
- name: Build
run: go build -ldflags "-s -w" -o ${REPO_NAME}_v${RELEASE_VERSION} -trimpath .
- name: Rename binary for windows
run: |
if [[ "${{ matrix.goos }}" == "windows" ]] ; then
mv ${REPO_NAME}_v${RELEASE_VERSION} ${REPO_NAME}_v${RELEASE_VERSION}.exe
fi
- name: Create archive zip
run: zip ${REPO_NAME}_${RELEASE_VERSION}_${{ matrix.goos }}_${{ matrix.goarch }}.zip ${REPO_NAME}_v${RELEASE_VERSION}*
- name: Upload archive zip to release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.RELEASE_TOKEN }}
allowUpdates: true
omitNameDuringUpdate: true
omitBodyDuringUpdate: true
omitDraftDuringUpdate: true
omitPrereleaseDuringUpdate: true
artifactContentType: application/zip
artifacts: "${{ env.REPO_NAME }}_${{ env.RELEASE_VERSION }}_*.zip"
shasum_zip:
name: Create sha256 sum for each zip
needs: [release,assets]
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Install utils
run: |
sudo apt update
sudo apt install -y jq libdigest-sha-perl
- name: Set env
run: |
echo "RELEASE_VERSION=$(echo ${GITHUB_REF} | cut -d'/' -f3 | sed 's/^v//')" >> $GITHUB_ENV
echo "REPO_NAME=$(echo ${GITHUB_REPOSITORY} | cut -d'/' -f2)" >> $GITHUB_ENV
echo "USER_NAME=$(echo ${GITHUB_REPOSITORY} | cut -d'/' -f1)" >> $GITHUB_ENV
- name: Download zip
run: |
for asset in $(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ env.USER_NAME }}/${{ env.REPO_NAME }}/releases/${{ needs.release.outputs.id }} | \
jq -r '.assets[] | .url+","+.name')
do
asset_url=$(echo ${asset} | cut -d',' -f1)
asset_name=$(echo ${asset} | cut -d',' -f2)
curl -J -L -H "Accept: application/octet-stream" -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
${asset_url} -o ${asset_name}
done
- name: List files
run: ls -la
- name: Rename registry manifest json file
run: cp terraform-registry-manifest.json ${{ env.REPO_NAME }}_${{ env.RELEASE_VERSION }}_manifest.json
- name: Generate SHA256SUMS
run: shasum -a 256 ${{ env.REPO_NAME }}_${{ env.RELEASE_VERSION }}_*.zip ${{ env.REPO_NAME }}_${{ env.RELEASE_VERSION }}_manifest.json > ${{ env.REPO_NAME }}_${{ env.RELEASE_VERSION }}_SHA256SUMS
- name: Upload shasum result
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.RELEASE_TOKEN }}
allowUpdates: true
omitNameDuringUpdate: true
omitBodyDuringUpdate: true
omitDraftDuringUpdate: true
omitPrereleaseDuringUpdate: true
artifactContentType: application/octet-stream
artifacts: ${{ env.REPO_NAME }}_${{ env.RELEASE_VERSION }}_SHA256SUMS,${{ env.REPO_NAME }}_${{ env.RELEASE_VERSION }}_manifest.json