-
Notifications
You must be signed in to change notification settings - Fork 0
173 lines (151 loc) · 4.88 KB
/
Copy pathrelease.yml
File metadata and controls
173 lines (151 loc) · 4.88 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
name: Release
on:
push:
tags:
- "v*"
permissions:
contents: write
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Run tests
run: go test ./...
build:
needs: test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- goos: linux
goarch: amd64
archive_ext: tar.gz
- goos: linux
goarch: arm64
archive_ext: tar.gz
- goos: darwin
goarch: amd64
archive_ext: tar.gz
- goos: darwin
goarch: arm64
archive_ext: tar.gz
- goos: windows
goarch: amd64
archive_ext: zip
- goos: windows
goarch: arm64
archive_ext: zip
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Show build context
shell: bash
run: |
set -euo pipefail
echo "ref=${GITHUB_REF_NAME}"
echo "runner=$(uname -a)"
go version
go env GOOS GOARCH CGO_ENABLED GOPATH GOMODCACHE GOCACHE
- name: Build archive
shell: bash
run: |
set -euo pipefail
version="${GITHUB_REF_NAME}"
dist="dist"
binary="codegraph"
binary_name="${binary}"
if [ "${{ matrix.goos }}" = "windows" ]; then
binary_name="${binary}.exe"
fi
archive_base="${binary}_${version}_${{ matrix.goos }}_${{ matrix.goarch }}"
mkdir -p "${dist}/${archive_base}"
GOOS="${{ matrix.goos }}" GOARCH="${{ matrix.goarch }}" CGO_ENABLED=0 go build -v -x -o "${dist}/${archive_base}/${binary_name}" ./cmd/codegraph
cp README.md "${dist}/${archive_base}/README.md"
cp LICENSE "${dist}/${archive_base}/LICENSE"
if [ "${{ matrix.archive_ext }}" = "zip" ]; then
(
cd "${dist}/${archive_base}"
zip -q -r "../${archive_base}.zip" .
)
sha256sum "${dist}/${archive_base}.zip" > "${dist}/${archive_base}.zip.sha256"
else
tar -C "${dist}" -czf "${dist}/${archive_base}.tar.gz" "${archive_base}"
sha256sum "${dist}/${archive_base}.tar.gz" > "${dist}/${archive_base}.tar.gz.sha256"
fi
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: release-${{ matrix.goos }}-${{ matrix.goarch }}
path: |
dist/*.tar.gz
dist/*.tar.gz.sha256
dist/*.zip
dist/*.zip.sha256
release:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Download all build artifacts
uses: actions/download-artifact@v4
with:
path: dist
- name: Flatten downloaded artifacts
shell: bash
run: |
set -euo pipefail
mkdir -p release-dist
find dist -type f \( -name "*.tar.gz" -o -name "*.tar.gz.sha256" -o -name "*.zip" -o -name "*.zip.sha256" \) -exec cp {} release-dist/ \;
- name: Extract release notes from CHANGELOG.md
shell: bash
run: |
set -euo pipefail
version="${GITHUB_REF_NAME}"
section_header="## ${version} -"
awk -v header="$section_header" '
BEGIN { found=0 }
$0 ~ /^## / && found { exit }
index($0, header) == 1 { found=1 }
found { print }
' CHANGELOG.md > release-notes-full.md
if ! grep -q "^## ${version} -" release-notes-full.md; then
echo "Could not find release notes section for tag ${version} in CHANGELOG.md"
exit 1
fi
tail -n +2 release-notes-full.md > release-notes.md
- name: Create or update GitHub release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
set -euo pipefail
if gh release view "${GITHUB_REF_NAME}" >/dev/null 2>&1; then
gh release edit "${GITHUB_REF_NAME}" \
--title "${GITHUB_REF_NAME}" \
--notes-file release-notes.md
else
gh release create "${GITHUB_REF_NAME}" \
--title "${GITHUB_REF_NAME}" \
--notes-file release-notes.md
fi
- name: Upload release assets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
set -euo pipefail
gh release upload "${GITHUB_REF_NAME}" release-dist/* --clobber