Skip to content

Commit 44f8e8b

Browse files
committed
feat: add auto-release on push to main
1 parent 5d08fb7 commit 44f8e8b

2 files changed

Lines changed: 60 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v5
18+
with:
19+
go-version: '1.23'
20+
21+
- name: Run tests
22+
run: go test ./... -v
23+
24+
- name: Run vet
25+
run: go vet ./...
26+
27+
- name: Build
28+
run: go build ./cmd/pathdigest/

.github/workflows/release.yml

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,57 @@ name: Release pathdigest
22

33
on:
44
push:
5+
branches: [main]
56
tags:
67
- 'v[0-9]+.[0-9]+.[0-9]+*'
78

89
permissions:
910
contents: write
1011

1112
jobs:
12-
goreleaser:
13+
release:
1314
runs-on: ubuntu-latest
1415
steps:
1516
- name: Checkout code
1617
uses: actions/checkout@v4
1718
with:
1819
fetch-depth: 0
19-
20+
2021
- name: Set up Go
2122
uses: actions/setup-go@v5
2223
with:
23-
go-version: '1.21'
24+
go-version: '1.23'
25+
26+
- name: Run tests before release
27+
run: go test ./... -v
28+
29+
- name: Get version info
30+
id: version
31+
run: |
32+
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
33+
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
34+
echo "is_tag=true" >> $GITHUB_OUTPUT
35+
else
36+
# Auto-generate version based on date and short SHA
37+
VERSION="v0.0.0-$(date +%Y%m%d)-${GITHUB_SHA::7}"
38+
echo "version=$VERSION" >> $GITHUB_OUTPUT
39+
echo "is_tag=false" >> $GITHUB_OUTPUT
40+
fi
41+
42+
- name: Create tag for main branch push
43+
if: steps.version.outputs.is_tag == 'false'
44+
run: |
45+
git config user.name "github-actions[bot]"
46+
git config user.email "github-actions[bot]@users.noreply.github.com"
47+
git tag ${{ steps.version.outputs.version }}
48+
git push origin ${{ steps.version.outputs.version }}
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2451

2552
- name: Run GoReleaser
26-
uses: goreleaser/goreleaser-action@v5
53+
uses: goreleaser/goreleaser-action@v6
2754
with:
55+
version: latest
2856
args: release --clean
2957
env:
3058
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)