Skip to content

Commit 217cfde

Browse files
authored
Merge pull request #1 from BrightlySoftware/add-arm
Update release.yml
2 parents 97aee38 + 44a73b2 commit 217cfde

File tree

1 file changed

+85
-73
lines changed

1 file changed

+85
-73
lines changed

.github/workflows/release.yml

Lines changed: 85 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -4,79 +4,91 @@ on:
44
workflow_dispatch:
55

66
jobs:
7-
87
release:
98
runs-on: ubuntu-latest
109
steps:
11-
- uses: actions/checkout@v2
12-
with:
13-
fetch-depth: 0
14-
15-
- name : Setup test
16-
run: 'echo "$PRIVATE_KEY" > gha-token-test.private-key.pem'
17-
shell: bash
18-
env:
19-
PRIVATE_KEY: ${{secrets.PRIVATE_KEY}}
20-
21-
- name: Set up Go
22-
uses: actions/setup-go@v2
23-
with:
24-
go-version: 1.17
25-
26-
- name: Lint
27-
uses: golangci/golangci-lint-action@v2
28-
29-
- name: Build
30-
run: go build -v ./...
31-
32-
- name: Test
33-
run: go test -v ./...
34-
35-
- name: Get Release Version from CHANGELOG
36-
id: get-release-version
37-
run: |
38-
RELEASE_VERSION="$(cat CHANGELOG.md | grep '^## \[[0-9]' | head -n1 | sed -e 's/^.*\[//' -e 's/\].*$//')"
39-
echo "Release Version in CHANGELOG: ${RELEASE_VERSION}"
40-
[ -n "${RELEASE_VERSION}" ]
41-
echo "::set-output name=RELEASE_VERSION::${RELEASE_VERSION}"
42-
43-
- name: Get Release Notes from CHANGELOG
44-
id: get-release-notes
45-
run: |
46-
RELEASE_NOTES="$(cat CHANGELOG.md | awk 'BEGIN {st=0} /^## \[[0-9]/ {st++; next} st==1 {print $0}')"
47-
RELEASE_NOTES="${RELEASE_NOTES//'%'/'%25'}"
48-
RELEASE_NOTES="${RELEASE_NOTES//$'\n'/'%0A'}"
49-
RELEASE_NOTES="${RELEASE_NOTES//$'\r'/'%0D'}"
50-
echo "::set-output name=RELEASE_NOTES::${RELEASE_NOTES}"
51-
52-
- name: Ensure Release Tag Does Not Exist
53-
run: '! git rev-parse -q --verify "refs/tags/${{ steps.get-release-version.outputs.RELEASE_VERSION }}" >/dev/null'
54-
55-
- name: Create Release Artifacts
56-
run: |
57-
mkdir -p build/darwin build/linux
58-
GOOS=linux GOARCH=amd64 go build -o build/linux/gha-token
59-
tar -c -C build/linux -f build/gha-token_${{ steps.get-release-version.outputs.RELEASE_VERSION }}_linux_amd64.tar.gz gha-token
60-
GOOS=darwin GOARCH=amd64 go build -o build/darwin/gha-token
61-
tar -c -C build/darwin -f build/gha-token_${{ steps.get-release-version.outputs.RELEASE_VERSION }}_darwin_amd64.tar.gz gha-token
62-
63-
- name: Create Release Tag
64-
uses: actions/github-script@v3
65-
with:
66-
github-token: ${{ secrets.GITHUB_TOKEN }}
67-
script: |
68-
github.git.createRef({
69-
owner: context.repo.owner,
70-
repo: context.repo.repo,
71-
ref: "refs/tags/${{ steps.get-release-version.outputs.RELEASE_VERSION }}",
72-
sha: context.sha
73-
})
74-
75-
- name: Publish Release
76-
uses: ncipollo/release-action@v1
77-
with:
78-
artifacts: "build/*.tar.gz"
79-
name: "${{ steps.get-release-version.outputs.RELEASE_VERSION }}"
80-
body: "${{ steps.get-release-notes.outputs.RELEASE_NOTES }}"
81-
tag: "${{ steps.get-release-version.outputs.RELEASE_VERSION }}"
82-
token: ${{ secrets.GITHUB_TOKEN }}
10+
- name: Checkout Repository
11+
uses: actions/checkout@v4
12+
with:
13+
fetch-depth: 0
14+
15+
- name: Setup Test
16+
run: echo "${{ secrets.PRIVATE_KEY }}" > gha-token-test.private-key.pem
17+
18+
- name: Set up Go
19+
uses: actions/setup-go@v4
20+
with:
21+
go-version: '1.21' # Updated Go version to a modern LTS release
22+
23+
- name: Run Linter
24+
uses: golangci/golangci-lint-action@v6
25+
with:
26+
version: latest
27+
28+
- name: Build
29+
run: go build -v ./...
30+
31+
- name: Run Tests
32+
run: go test -v ./...
33+
34+
- name: Get Release Version from CHANGELOG
35+
id: get-release-version
36+
run: |
37+
RELEASE_VERSION=$(grep '^## \[[0-9]' CHANGELOG.md | head -n1 | sed -e 's/^.*\[//' -e 's/\].*$//')
38+
echo "Release Version in CHANGELOG: ${RELEASE_VERSION}"
39+
[ -n "${RELEASE_VERSION}" ] || { echo "Error: No version found in CHANGELOG"; exit 1; }
40+
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV
41+
42+
- name: Get Release Notes from CHANGELOG
43+
id: get-release-notes
44+
run: |
45+
RELEASE_NOTES=$(awk 'BEGIN {st=0} /^## \[[0-9]/ {st++; next} st==1 {print $0}' CHANGELOG.md)
46+
RELEASE_NOTES="${RELEASE_NOTES//'%'/'%25'}"
47+
RELEASE_NOTES="${RELEASE_NOTES//$'\n'/'%0A'}"
48+
RELEASE_NOTES="${RELEASE_NOTES//$'\r'/'%0D'}"
49+
echo "RELEASE_NOTES=${RELEASE_NOTES}" >> $GITHUB_ENV
50+
51+
- name: Ensure Release Tag Does Not Exist
52+
run: |
53+
if git rev-parse -q --verify "refs/tags/${RELEASE_VERSION}" >/dev/null; then
54+
echo "Error: Release tag ${RELEASE_VERSION} already exists!"
55+
exit 1
56+
fi
57+
58+
- name: Create Release Artifacts
59+
run: |
60+
mkdir -p build/darwin build/linux
61+
62+
# Linux x86_64 (amd64)
63+
GOOS=linux GOARCH=amd64 go build -o build/linux/gha-token
64+
tar -czf build/gha-token_${RELEASE_VERSION}_linux_amd64.tar.gz -C build/linux gha-token
65+
66+
# macOS x86_64 (Intel)
67+
GOOS=darwin GOARCH=amd64 go build -o build/darwin/gha-token
68+
tar -czf build/gha-token_${RELEASE_VERSION}_darwin_amd64.tar.gz -C build/darwin gha-token
69+
70+
# macOS arm64 (Apple Silicon: M1/M2/M3)
71+
GOOS=darwin GOARCH=arm64 go build -o build/darwin/gha-token-arm64
72+
tar -czf build/gha-token_${RELEASE_VERSION}_darwin_arm64.tar.gz -C build/darwin gha-token-arm64
73+
74+
- name: Create Release Tag
75+
uses: actions/github-script@v7
76+
with:
77+
github-token: ${{ secrets.GITHUB_TOKEN }}
78+
script: |
79+
const releaseVersion = process.env.RELEASE_VERSION;
80+
github.rest.git.createRef({
81+
owner: context.repo.owner,
82+
repo: context.repo.repo,
83+
ref: `refs/tags/${releaseVersion}`,
84+
sha: context.sha
85+
});
86+
87+
- name: Publish Release
88+
uses: ncipollo/release-action@v1
89+
with:
90+
artifacts: "build/*.tar.gz"
91+
name: "${{ env.RELEASE_VERSION }}"
92+
body: "${{ env.RELEASE_NOTES }}"
93+
tag: "${{ env.RELEASE_VERSION }}"
94+
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)