Repository navigation
82 lines (74 loc) · 3.15 KB
/
Copy pathrelease.yml
File metadata and controls
82 lines (74 loc) · 3.15 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
# Release: push the root tag vX.Y.Z and this cross-compiles the sqlshape binary for every
# platform, packs it, and publishes a GitHub Release with checksums.
#
# scripts/release.sh v1.3.0 --push
#
# The repository's modules (the root, postgres, mysql, mysqltest, pgtest, check/postgres,
# check/mysql, cmd/sqlshape) release in lockstep: scripts/release.sh sets the inter-module requires to
# the version, commits, and tags vX.Y.Z and <module>/vX.Y.Z on that commit. Only the root
# tag triggers this workflow (the others do not start with "v").
#
# The binary is a plain Go build (libpg_query runs as WebAssembly, no cgo), so one runner
# builds every target; the smoke test runs the runner's own (linux/amd64) binary as a
# vettool over the examples, the only one it can execute.
#
# `go install github.com/kr9ly/sqlshape/cmd/sqlshape/v2@<version>` needs nothing from this
# workflow: it reads the tag cmd/sqlshape/<version> straight from the module proxy.
name: release
on:
push:
tags: ["v*"]
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Version
run: echo "VERSION=${GITHUB_REF_NAME}" >> "$GITHUB_ENV"
- name: Build
env:
CGO_ENABLED: "0"
run: |
mkdir dist
for target in linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64 windows/arm64; do
goos=${target%/*}; goarch=${target#*/}
bin=sqlshape; [ "$goos" = windows ] && bin=sqlshape.exe
GOOS=$goos GOARCH=$goarch go build -trimpath \
-ldflags "-s -w -X github.com/kr9ly/sqlshape/cmd/sqlshape/v2/internal/cli.version=${VERSION}" \
-o "build/$goos-$goarch/$bin" ./cmd/sqlshape
name="sqlshape_${VERSION}_${goos}_${goarch}"
mkdir "$name"
cp "build/$goos-$goarch/$bin" cmd/sqlshape/LICENSE check/postgres/NOTICE README.md "$name"/
if [ "$goos" = windows ]; then
zip -qr "dist/$name.zip" "$name"
else
tar -czf "dist/$name.tar.gz" "$name"
fi
rm -r "$name"
done
ls -la dist
- name: Smoke test
run: .github/scripts/smoke.sh ./build/linux-amd64/sqlshape "$VERSION"
- name: Checksums
run: cd dist && sha256sum sqlshape_* > checksums.txt
- name: Publish
env:
GH_TOKEN: ${{ github.token }}
run: |
pre=""
case "$VERSION" in *-*) pre="--prerelease" ;; esac # v1.3.0-rc.1
# the release notes are the version's section of CHANGELOG.md (a candidate v1.3.0-rc.1
# reads the 1.3.0 section); generated notes when it has none
v="${VERSION#v}"; v="${v%%-*}"
awk -v v="$v" '/^## \[/ { on = index($0, "[" v "]") > 0; next } on' CHANGELOG.md > notes.md
notes="--generate-notes"
if grep -q . notes.md; then notes="--notes-file notes.md"; fi
gh release create "$GITHUB_REF_NAME" dist/* \
--repo "$GITHUB_REPOSITORY" \
--title "sqlshape $VERSION" \
$notes $pre