55 branches : [main]
66
77jobs :
8+ check-skip :
9+ runs-on : ubuntu-latest
10+ outputs :
11+ should_skip : ${{ steps.check.outputs.skip }}
12+ steps :
13+ - name : Check if this is a version bump commit
14+ id : check
15+ run : |
16+ MSG="${{ github.event.head_commit.message }}"
17+ if echo "$MSG" | grep -q "^chore: bump version"; then
18+ echo "skip=true" >> $GITHUB_OUTPUT
19+ else
20+ echo "skip=false" >> $GITHUB_OUTPUT
21+ fi
22+
823 version :
24+ needs : [check-skip]
25+ if : needs.check-skip.outputs.should_skip == 'false'
926 runs-on : ubuntu-latest
1027 outputs :
1128 new_version : ${{ steps.bump.outputs.new_version }}
29+ old_version : ${{ steps.bump.outputs.old_version }}
1230 steps :
1331 - uses : actions/checkout@v5
1432 with :
1533 fetch-depth : 0
16- - name : Install tools
17- run : |
18- sudo apt-get update
19- sudo apt-get install -y python python-pip
20- pip install --user bumpver
21- - name : Calculate version bump
34+ - name : Determine version bump
2235 id : bump
2336 run : |
24- LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
25- if [ -n "$LAST_TAG" ]; then
26- COMMITS=$(git log $LAST_TAG..HEAD --pretty=%s)
27- else
28- COMMITS=$(git log HEAD --pretty=%s)
37+ LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
38+ OLD_VERSION=${LAST_TAG#v}
39+ IFS='.' read -r MAJOR MINOR PATCH <<< "$OLD_VERSION"
40+
41+ COMMITS=$(git log ${LAST_TAG}..HEAD --pretty=%s 2>/dev/null || git log HEAD --pretty=%s)
42+
43+ if echo "$COMMITS" | grep -q "^feat:"; then
44+ MINOR=$((MINOR + 1))
45+ PATCH=0
46+ elif echo "$COMMITS" | grep -q "^chore:\|^fix:\|^docs:"; then
47+ PATCH=$((PATCH + 1))
2948 fi
49+
3050 if echo "$COMMITS" | grep -q "^BREAKING CHANGE:"; then
31- bumpver update --major
32- elif echo "$COMMITS" | grep -q "^feat:"; then
33- bumpver update --minor
34- else
35- bumpver update --patch
51+ MAJOR=$((MAJOR + 1))
52+ MINOR=0
53+ PATCH=0
3654 fi
37- NEW_VERSION=$(bumpver show | grep -E "^[0-9]+\.[0-9]+\.[0-9]+" | head -1)
55+
56+ NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
3857 echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
39- - name : Bump PKGBUILD versions
40- run : |
41- sed -i "s/pkgver=.*/pkgver=${{ steps.bump.outputs.new_version }}/" PKGBUILD
42- sed -i "s/pkgver=.*/pkgver=${{ steps.bump.outputs.new_version }}/" aur/PKGBUILD
43- cd aur && makepkg --printsrcinfo > .SRCINFO
44- - name : Upload version files (uncommitted)
45- uses : actions/upload-artifact@v6
46- with :
47- name : version-files
48- path : |
49- PKGBUILD
50- aur/
58+ echo "old_version=$OLD_VERSION" >> $GITHUB_OUTPUT
59+ echo "Bumping $OLD_VERSION -> $NEW_VERSION"
5160
5261 build :
5362 needs : [version]
5665 - uses : actions/checkout@v5
5766 with :
5867 fetch-depth : 0
59- - uses : actions/download-artifact@v7
60- with :
61- name : version-files
62- path : .
6368 - name : Install system dependencies
6469 run : |
6570 sudo apt-get update
@@ -76,90 +81,118 @@ jobs:
7681 elif [ "$ARCH" = "aarch64" ]; then
7782 echo "arch_name=aarch64" >> $GITHUB_OUTPUT
7883 fi
84+ - name : Update PKGBUILD versions
85+ run : |
86+ VERSION=${{ needs.version.outputs.new_version }}
87+ sed -i "s/pkgver=.*/pkgver=$VERSION/" PKGBUILD
88+ sed -i "s/pkgver=.*/pkgver=$VERSION/" aur/PKGBUILD
7989 - name : Create tarball
8090 run : |
81- mkdir -p krosshair-${{ needs.version.outputs.new_version }}-${{ steps.arch.outputs.arch_name }}
82- cp lib/krosshair.so krosshair-${{ needs.version.outputs.new_version }}-${{ steps.arch.outputs.arch_name }}/
83- cp krosshair.json krosshair-${{ needs.version.outputs.new_version }}-${{ steps.arch.outputs.arch_name }}/
84- cp LICENSE krosshair-${{ needs.version.outputs.new_version }}-${{ steps.arch.outputs.arch_name }}/ 2>/dev/null || true
85- tar -czf krosshair-${{ needs.version.outputs.new_version }}-${{ steps.arch.outputs.arch_name }}.tar.gz -C krosshair-${{ needs.version.outputs.new_version }}-${{ steps.arch.outputs.arch_name }} .
86- - name : Generate checksum
87- run : sha256sum krosshair-${{ needs.version.outputs.new_version }}-${{ steps.arch.outputs.arch_name }}.tar.gz > krosshair-${{ needs.version.outputs.new_version }}-${{ steps.arch.outputs.arch_name }}.sha256
88- - name : Upload artifacts
91+ ARCH_NAME=${{ steps.arch.outputs.arch_name }}
92+ VERSION=${{ needs.version.outputs.new_version }}
93+ mkdir -p krosshair-linux-${ARCH_NAME}
94+ cp lib/krosshair.so krosshair-linux-${ARCH_NAME}/
95+ cp krosshair.json krosshair-linux-${ARCH_NAME}/
96+ cp LICENSE krosshair-linux-${ARCH_NAME}/ 2>/dev/null || true
97+ tar -czf krosshair-linux-${ARCH_NAME}.tar.gz -C krosshair-linux-${ARCH_NAME} .
98+ sha256sum krosshair-linux-${ARCH_NAME}.tar.gz > krosshair-linux-${ARCH_NAME}.sha256
99+ - name : Upload build artifacts
89100 uses : actions/upload-artifact@v6
90101 with :
91- name : krosshair-${{ needs.version.outputs.new_version }}-${{ steps.arch.outputs.arch_name }}
102+ name : build-output
92103 path : |
93- krosshair-*.tar.gz
94- krosshair-*.sha256
104+ PKGBUILD
105+ aur/
106+ krosshair-linux-*.tar.gz
107+ krosshair-linux-*.sha256
95108
96- commit-and- release :
109+ release :
97110 needs : [version, build]
98111 runs-on : ubuntu-latest
112+ permissions :
113+ contents : write
99114 steps :
100115 - uses : actions/checkout@v5
101116 with :
102117 ref : main
103118 fetch-depth : 0
104119 - uses : actions/download-artifact@v7
105120 with :
106- path : artifacts
107- - name : Restore version files from successful build
108- run : |
109- mkdir -p aur
110- cp artifacts/version-files/PKGBUILD .
111- cp -r artifacts/version-files/aur/* aur/
112- - name : Commit version bump and create tag
121+ name : build-output
122+ path : .
123+ - name : Configure git
113124 run : |
114125 git config user.name "GitHub Action"
115126 git config user.email "action@github.com"
127+ gh auth setup-git
128+ env :
129+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
130+ - name : Commit version bump and tag
131+ run : |
132+ VERSION=${{ needs.version.outputs.new_version }}
116133 git add PKGBUILD aur/
117- git commit -m "chore: bump version to v${{ needs.version.outputs.new_version } }" || echo "No changes to commit"
118- git tag "v${{ needs.version.outputs.new_version } }" -f
134+ git commit -m "chore: bump version to v${VERSION }" || echo "No changes to commit"
135+ git tag "v${VERSION }" -f
119136 git push origin main
120- git push origin "v${{ needs.version.outputs.new_version }}" -f
137+ git push origin "v${VERSION}" -f
138+ env :
139+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
140+ - name : Create GitHub release
141+ run : |
142+ VERSION=${{ needs.version.outputs.new_version }}
143+ ARCH_NAME=$(uname -m)
144+ if [ "$ARCH_NAME" = "x86_64" ]; then
145+ ARCH_NAME="x86_64"
146+ elif [ "$ARCH_NAME" = "aarch64" ]; then
147+ ARCH_NAME="aarch64"
148+ fi
149+ gh release delete "v${VERSION}" --yes 2>/dev/null || true
150+ gh release create "v${VERSION}" \
151+ --title "v${VERSION}" \
152+ --notes "Release v${VERSION}" \
153+ krosshair-linux-${ARCH_NAME}.tar.gz \
154+ krosshair-linux-${ARCH_NAME}.sha256
121155 env :
122156 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
157+
158+ aur :
159+ needs : [version, build, release]
160+ runs-on : ubuntu-latest
161+ container : archlinux:latest
162+ steps :
163+ - uses : actions/download-artifact@v7
164+ with :
165+ name : build-output
166+ path : .
123167 - name : Push to AUR
124168 run : |
169+ VERSION=${{ needs.version.outputs.new_version }}
170+ pacman -Sy --noconfirm openssh git
125171 mkdir -p ~/.ssh
126172 echo "$AUR_SSH_KEY" > ~/.ssh/aur
127173 chmod 600 ~/.ssh/aur
128174 ssh-keyscan aur.archlinux.org >> ~/.ssh/known_hosts
129- rm -rf aur
130- if git clone ssh://aur@aur.archlinux.org/krosshair.git aur 2>&1; then
175+
176+ if git clone ssh://aur@aur.archlinux.org/krosshair.git aur-push 2>&1; then
131177 echo "Cloned existing AUR repo"
132- cp -r artifacts/version-files/aur/* aur/
133- cd aur
134178 else
135179 echo "Creating new AUR repo"
136- mkdir aur
137- cp -r artifacts/version-files/aur/* aur/
138- cd aur
180+ mkdir -p aur-push
181+ cd aur-push
139182 git init
140183 git remote add origin ssh://aur@aur.archlinux.org/krosshair.git
184+ cd ..
141185 fi
186+
187+ cp aur/PKGBUILD aur-push/
188+ cp aur/krosshair.install aur-push/
189+
190+ cd aur-push
142191 makepkg --printsrcinfo > .SRCINFO
143192 git config user.name "GitHub Action"
144193 git config user.email "action@github.com"
145194 git add PKGBUILD .SRCINFO krosshair.install
146- git commit -m "Update to v${{ needs.version.outputs.new_version } }" || echo "No changes to commit"
195+ git commit -m "Update to v${VERSION }" || echo "No changes to commit"
147196 git push origin master
148197 env :
149198 AUR_SSH_KEY : ${{ secrets.AUR_SSH_KEY }}
150- - name : Create release with assets
151- run : |
152- ARCH=$(uname -m)
153- if [ "$ARCH" = "x86_64" ]; then
154- ARCH_NAME="x86_64"
155- elif [ "$ARCH" = "aarch64" ]; then
156- ARCH_NAME="aarch64"
157- fi
158- gh release delete "v${{ needs.version.outputs.new_version }}" --yes 2>/dev/null || true
159- gh release create "v${{ needs.version.outputs.new_version }}" \
160- --title "v${{ needs.version.outputs.new_version }}" \
161- --notes "Release v${{ needs.version.outputs.new_version }}" \
162- artifacts/krosshair-${{ needs.version.outputs.new_version }}-${ARCH_NAME}/krosshair-${{ needs.version.outputs.new_version }}-${ARCH_NAME}.tar.gz \
163- artifacts/krosshair-${{ needs.version.outputs.new_version }}-${ARCH_NAME}/krosshair-${{ needs.version.outputs.new_version }}-${ARCH_NAME}.sha256
164- env :
165- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments