-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (93 loc) · 3.3 KB
/
Copy pathrelease.yml
File metadata and controls
108 lines (93 loc) · 3.3 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
name: Release
on:
workflow_dispatch:
inputs:
bump:
description: "Version bump type"
required: true
default: "patch"
type: choice
options:
- patch
- minor
permissions:
contents: write
jobs:
release:
name: Build & Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.24"
- name: Determine version
id: version
run: |
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
VERSION=${LATEST_TAG#v}
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
if [ "${{ inputs.bump }}" = "minor" ]; then
MINOR=$((MINOR + 1))
PATCH=0
else
PATCH=$((PATCH + 1))
fi
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
echo "tag=v${NEW_VERSION}" >> "$GITHUB_OUTPUT"
echo "prev_tag=$LATEST_TAG" >> "$GITHUB_OUTPUT"
echo "Bumping $LATEST_TAG → v${NEW_VERSION} (${{ inputs.bump }})"
- name: Update version in main.go
run: |
sed -i "s/var version = \".*\"/var version = \"${{ steps.version.outputs.version }}\"/" main.go
grep 'var version' main.go
- name: Run tests
run: go test -race -count=1 ./...
- name: Cross-compile binaries
run: |
mkdir -p dist
TARGETS="linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64"
for target in $TARGETS; do
GOOS="${target%/*}"
GOARCH="${target#*/}"
OUTPUT="dist/rawdoc-${GOOS}-${GOARCH}"
if [ "$GOOS" = "windows" ]; then
OUTPUT="${OUTPUT}.exe"
fi
echo "Building $OUTPUT"
GOOS=$GOOS GOARCH=$GOARCH go build -ldflags="-s -w" -o "$OUTPUT" .
done
ls -lh dist/
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Commit version bump and create tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git add main.go
git diff --cached --quiet && echo "No version change to commit" || \
git commit -m "release: v${{ steps.version.outputs.version }}"
git tag -a "${{ steps.version.outputs.tag }}" -m "Release ${{ steps.version.outputs.tag }}
Install: go install github.com/RandomCodeSpace/rawdoc@${{ steps.version.outputs.tag }}"
git push origin HEAD:main --tags
- name: Create GitHub release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PREV_TAG="${{ steps.version.outputs.prev_tag }}"
NOTES_FLAG=""
if [ "$PREV_TAG" != "v0.0.0" ] && git rev-parse "$PREV_TAG" >/dev/null 2>&1; then
NOTES_FLAG="--notes-start-tag $PREV_TAG"
fi
gh release create "${{ steps.version.outputs.tag }}" \
dist/* \
--title "rawdoc ${{ steps.version.outputs.tag }}" \
--generate-notes \
$NOTES_FLAG