-
Notifications
You must be signed in to change notification settings - Fork 1
177 lines (167 loc) · 5.42 KB
/
release.yml
File metadata and controls
177 lines (167 loc) · 5.42 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
174
175
176
177
name: Release
on:
push:
tags:
- v*
workflow_dispatch: {}
permissions:
contents: write
checks: read
jobs:
docker_build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- uses: actions/github-script@v7
with:
script: |
const script = require('./.github/wait-for-checks.js');
await script({ github, context, core });
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Extract version info
run: |
if [ "${{ github.event_name }}" = "push" ]; then
TAG="${GITHUB_REF#refs/tags/}"
echo "VERSION=${TAG#v}" >> "$GITHUB_ENV"
echo "GIT_TAG=${TAG}" >> "$GITHUB_ENV"
else
TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "latest")
echo "VERSION=${TAG#v}" >> "$GITHUB_ENV"
echo "GIT_TAG=${TAG}" >> "$GITHUB_ENV"
fi
echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> "$GITHUB_ENV"
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
push: true
build-args: |
COMMIT_SHA=${{ github.sha }}
tags: |
docker.io/docspringcom/rack-gateway:${{ env.COMMIT_SHA }}
docker.io/docspringcom/rack-gateway:latest
cache-from: type=gha
cache-to: type=gha,mode=max
release_build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- uses: actions/github-script@v7
with:
script: |
const script = require('./.github/wait-for-checks.js');
await script({ github, context, core });
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.25.7"
- name: Build binary
env:
CGO_ENABLED: 0
GOOS: linux
GOARCH: amd64
run: |
set -e
go build \
-tags nofido \
-buildvcs=false \
-ldflags "-s -w" \
-o rack-gateway-linux-amd64 \
./cmd/rack-gateway/
- name: Create archive
run: |
set -e
tar czf rack-gateway-linux-amd64.tar.gz rack-gateway-linux-amd64
echo "ASSET_PATH=rack-gateway-linux-amd64.tar.gz" >> "$GITHUB_ENV"
- uses: actions/upload-artifact@v4
with:
path: ${{ env.ASSET_PATH }}
name: rack-gateway-linux-amd64
release_create:
runs-on: ubuntu-latest
needs:
- release_build
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- uses: actions/download-artifact@v4
with:
name: rack-gateway-linux-amd64
path: artifacts/rack-gateway-linux-amd64
- run: |
if [ "${{ github.event_name }}" = "push" ]; then
TAG="${GITHUB_REF#refs/tags/}"
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
echo "Error: Invalid tag format $TAG (expected v*.*.* semver)" >&2
exit 1
fi
echo "RELEASE_TAG=$TAG" >> "$GITHUB_ENV"
VERSION="${TAG#v}"
echo "RELEASE_VERSION=$VERSION" >> "$GITHUB_ENV"
else
# For workflow_dispatch, use latest tag
TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$TAG" ]; then
echo "Error: No tags found. Cannot create release without a tag." >&2
exit 1
fi
echo "RELEASE_TAG=$TAG" >> "$GITHUB_ENV"
VERSION="${TAG#v}"
echo "RELEASE_VERSION=$VERSION" >> "$GITHUB_ENV"
fi
- name: Generate checksums
run: |
set -e
cd artifacts
for dir in */; do
cd "$dir"
for file in *; do
case "$file" in
*.tar.gz|*.zip)
if [ -f "$file" ]; then
sha256sum "$file" > "${file}.sha256" || shasum -a 256 "$file" | awk '{print $1}' > "${file}.sha256"
fi
;;
esac
done
cd ..
done
cd ..
- name: Generate changelog
run: |
cat > changelog.md <<EOF
## Installation
### Linux (x86_64)
curl -L https://github.com/${{ github.repository }}/releases/download/${{ env.RELEASE_TAG }}/rack-gateway-linux-amd64.tar.gz | tar xz
sudo mv rack-gateway-linux-amd64 /usr/local/bin/rack-gateway
sudo chmod +x /usr/local/bin/rack-gateway
rack-gateway version
EOF
- uses: softprops/action-gh-release@v2
with:
files: |
artifacts/**/*.tar.gz
artifacts/**/*.sha256
prerelease: ${{ contains(env.RELEASE_TAG, '-') }}
body_path: changelog.md
name: rack-gateway v${{ env.RELEASE_VERSION }}
draft: false
tag_name: ${{ env.RELEASE_TAG }}