-
Notifications
You must be signed in to change notification settings - Fork 0
71 lines (57 loc) · 2.06 KB
/
update-api-version.yaml
File metadata and controls
71 lines (57 loc) · 2.06 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
name: Update Version and Release
on:
push:
branches:
- main
paths:
- "CHANGELOG.md"
permissions:
contents: write
jobs:
update-version:
name: Update API Version
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Extract latest version from CHANGELOG.md
id: get_version
run: |
# Get the first heading line like: "## [1.1.2](...)"
LINE=$(grep -m1 -E '^## \[[0-9]+\.[0-9]+\.[0-9]+\]' CHANGELOG.md || true)
if [ -z "$LINE" ]; then
echo "Error: Could not find a version line in CHANGELOG.md"
exit 1
fi
# Extract just "1.1.2" from that line
VERSION=$(echo "$LINE" | sed -E 's/^## \[([0-9]+\.[0-9]+\.[0-9]+)\].*/\1/')
if [ -z "$VERSION" ]; then
echo "Error: Failed to extract version from line: $LINE"
exit 1
fi
echo "Found version: $VERSION"
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
- name: Update version in cmd/api/main.go
run: |
VERSION="${{ steps.get_version.outputs.VERSION }}"
if [ -z "$VERSION" ]; then
echo "Error: VERSION output from previous step is empty"
exit 1
fi
sed -i "s/const version = \".*\"/const version = \"$VERSION\"/" cmd/api/main.go
echo "Updated version in cmd/api/main.go to $VERSION"
- name: Commit and push changes
run: |
git config --global user.email "action@github.com"
git config --global user.name "GitHub Action"
git add cmd/api/main.go
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "Update API version to $(git log -1 --format=%s | sed 's/"/'\''/g')"
git commit --amend -m "Update API version to ${{ steps.get_version.outputs.VERSION }}" || true
git push
echo "Successfully pushed version update"
fi