forked from jwilder/dockerize
-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (96 loc) · 3.07 KB
/
Copy pathrelease.yml
File metadata and controls
113 lines (96 loc) · 3.07 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
name: Release
on:
workflow_dispatch:
inputs:
bump:
description: "Version bump type"
required: true
type: choice
options:
- patch
- minor
- major
permissions:
contents: write
packages: write
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Calculate next version
id: version
run: |
CURRENT=$(git describe --abbrev=0 --tags 2>/dev/null || echo "v0.0.0")
echo "current=$CURRENT" >> "$GITHUB_OUTPUT"
# Strip the 'v' prefix for arithmetic
VERSION=${CURRENT#v}
MAJOR=$(echo "$VERSION" | cut -d. -f1)
MINOR=$(echo "$VERSION" | cut -d. -f2)
PATCH=$(echo "$VERSION" | cut -d. -f3)
case "${{ inputs.bump }}" in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
esac
NEXT="v${MAJOR}.${MINOR}.${PATCH}"
echo "next=$NEXT" >> "$GITHUB_OUTPUT"
echo "Bumping $CURRENT -> $NEXT (${{ inputs.bump }})"
- name: Update version references in README.md
run: |
CURRENT=${{ steps.version.outputs.current }}
NEXT=${{ steps.version.outputs.next }}
sed -i "s|${CURRENT}|${NEXT}|g" README.md
- name: Update version references in examples
run: |
CURRENT=${{ steps.version.outputs.current }}
NEXT=${{ steps.version.outputs.next }}
find examples -name 'Dockerfile' -exec sed -i "s|${CURRENT}|${NEXT}|g" {} +
- name: Commit version bump
run: |
NEXT=${{ steps.version.outputs.next }}
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add README.md examples/
git commit -m "chore: bump version to ${NEXT}" || echo "No changes to commit"
git push
- name: Create and push tag
run: |
NEXT=${{ steps.version.outputs.next }}
git tag -a "${NEXT}" -m "Release ${NEXT}"
git push origin "${NEXT}"
- name: Log in to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v7
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}