forked from slawekzachcial/gha-token
-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (78 loc) · 3.2 KB
/
Copy pathrelease.yml
File metadata and controls
94 lines (78 loc) · 3.2 KB
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
name: Release
on:
workflow_dispatch:
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
# - name: Setup Test
# run: echo "${{ secrets.PRIVATE_KEY }}" > gha-token-test.private-key.pem
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21' # Updated Go version to a modern LTS release
- name: Run Linter
uses: golangci/golangci-lint-action@v6
with:
version: latest
- name: Build
run: go build -v ./...
# - name: Run Tests
# run: go test -v ./...
- name: Get Release Version from CHANGELOG
id: get-release-version
run: |
RELEASE_VERSION=$(grep '^## \[[0-9]' CHANGELOG.md | head -n1 | sed -e 's/^.*\[//' -e 's/\].*$//')
echo "Release Version in CHANGELOG: ${RELEASE_VERSION}"
[ -n "${RELEASE_VERSION}" ] || { echo "Error: No version found in CHANGELOG"; exit 1; }
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV
- name: Get Release Notes from CHANGELOG
id: get-release-notes
run: |
RELEASE_NOTES=$(awk 'BEGIN {st=0} /^## \[[0-9]/ {st++; next} st==1 {print $0}' CHANGELOG.md)
RELEASE_NOTES="${RELEASE_NOTES//'%'/'%25'}"
RELEASE_NOTES="${RELEASE_NOTES//$'\n'/'%0A'}"
RELEASE_NOTES="${RELEASE_NOTES//$'\r'/'%0D'}"
echo "RELEASE_NOTES=${RELEASE_NOTES}" >> $GITHUB_ENV
- name: Ensure Release Tag Does Not Exist
run: |
if git rev-parse -q --verify "refs/tags/${RELEASE_VERSION}" >/dev/null; then
echo "Error: Release tag ${RELEASE_VERSION} already exists!"
exit 1
fi
- name: Create Release Artifacts
run: |
mkdir -p build/darwin build/linux
# Linux x86_64 (amd64)
GOOS=linux GOARCH=amd64 go build -o build/linux/gha-token
tar -czf build/gha-token_${RELEASE_VERSION}_linux_amd64.tar.gz -C build/linux gha-token
# macOS x86_64 (Intel)
GOOS=darwin GOARCH=amd64 go build -o build/darwin/gha-token
tar -czf build/gha-token_${RELEASE_VERSION}_darwin_amd64.tar.gz -C build/darwin gha-token
# macOS arm64 (Apple Silicon: M1/M2/M3)
GOOS=darwin GOARCH=arm64 go build -o build/darwin/gha-token-arm64
tar -czf build/gha-token_${RELEASE_VERSION}_darwin_arm64.tar.gz -C build/darwin gha-token-arm64
- name: Create Release Tag
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const releaseVersion = process.env.RELEASE_VERSION;
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${releaseVersion}`,
sha: context.sha
});
- name: Publish Release
uses: ncipollo/release-action@v1
with:
artifacts: "build/*.tar.gz"
name: "${{ env.RELEASE_VERSION }}"
body: "${{ env.RELEASE_NOTES }}"
tag: "${{ env.RELEASE_VERSION }}"
token: ${{ secrets.GITHUB_TOKEN }}