Skip to content

Commit bdfd116

Browse files
committed
chore: add versioning support and release workflow
1 parent 4449c1d commit bdfd116

6 files changed

Lines changed: 230 additions & 43 deletions

File tree

.github/workflows/build.yml

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ on:
44
paths-ignore:
55
- '*.md'
66
- '.gitignore'
7-
pull_request:
8-
paths-ignore:
9-
- '*.md'
10-
- '.gitignore'
7+
- "src/version.h"
8+
- ".github/workflows/delete_old_workflow_runs.yml"
119
workflow_dispatch:
1210
inputs:
1311
version:
@@ -33,7 +31,24 @@ jobs:
3331
uses: actions/checkout@v4
3432
with:
3533
submodules: 'true'
36-
34+
35+
- name: Update version.h
36+
shell: bash
37+
run: |
38+
if [ "${{ github.event_name }}" == "push" ]; then
39+
COMMIT_HASH=$(git rev-parse --short HEAD)
40+
VERSION="alpha-${COMMIT_HASH}"
41+
echo "VERSION=$VERSION" >> $GITHUB_ENV
42+
sed -i '/#define RELEASE_VER_STR/,/TOSTRING(RELEASE_VER_FIX)/c\#define RELEASE_VER_STR "'$VERSION'"' src/version.h
43+
elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
44+
VERSION="${{ github.event.inputs.version }}"
45+
echo "VERSION=$VERSION" >> $GITHUB_ENV
46+
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
47+
sed -i 's/#define RELEASE_VER_MAIN .*/#define RELEASE_VER_MAIN '$MAJOR'/' src/version.h
48+
sed -i 's/#define RELEASE_VER_SUB .*/#define RELEASE_VER_SUB '$MINOR'/' src/version.h
49+
sed -i 's/#define RELEASE_VER_FIX .*/#define RELEASE_VER_FIX '$PATCH'/' src/version.h
50+
fi
51+
3752
- name: Setup VC-LTL
3853
run: nuget install VC-LTL
3954

@@ -55,45 +70,39 @@ jobs:
5570
name: setdll-${{ matrix.arch }}
5671
path: build/release/*
5772

58-
package:
59-
if: github.event_name == 'workflow_dispatch'
73+
create_pr:
6074
needs: build
6175
runs-on: ubuntu-latest
62-
76+
if: github.event_name == 'workflow_dispatch'
77+
6378
steps:
64-
- uses: actions/checkout@v4
65-
66-
- name: Download All Artifacts
67-
uses: actions/download-artifact@v4
68-
with:
69-
path: build_artifacts
70-
71-
- name: Prepare Release Files
72-
run: |
73-
for arch in x86 x64 arm64; do
74-
cp injectpe.bat build_artifacts/setdll-$arch
75-
cp README.md build_artifacts/setdll-$arch
76-
done
79+
- name: Checkout repository
80+
uses: actions/checkout@v4
7781

78-
- name: Create Archives
79-
run: |
80-
for arch in x86 x64 arm64; do
81-
cd build_artifacts/setdll-$arch
82-
zip -r ../setdll-$arch.zip .
83-
cd ../..
84-
done
82+
- name: Set up Git Configurations
83+
run: |
84+
git config user.name "github-actions[bot]"
85+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
86+
git checkout -b release
8587
86-
- name: Upload Archive Artifacts
87-
uses: actions/upload-artifact@v4
88-
with:
89-
name: setdll-release
90-
path: build_artifacts/*.zip
91-
92-
- name: Create Release
93-
uses: softprops/action-gh-release@v2
94-
with:
95-
files: build_artifacts/**/*
96-
tag_name: ${{ github.event.inputs.version }}
97-
name: ${{ github.event.inputs.version }}
98-
env:
99-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
- name: Update version.h
89+
run: |
90+
VERSION="${{ github.event.inputs.version }}"
91+
echo "VERSION=$VERSION" >> $GITHUB_ENV
92+
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
93+
sed -i 's/#define RELEASE_VER_MAIN .*/#define RELEASE_VER_MAIN '"$MAJOR"'/' src/version.h
94+
sed -i 's/#define RELEASE_VER_SUB .*/#define RELEASE_VER_SUB '"$MINOR"'/' src/version.h
95+
sed -i 's/#define RELEASE_VER_FIX .*/#define RELEASE_VER_FIX '"$PATCH"'/' src/version.h
96+
git add src/version.h
97+
git commit -m "build(release): bump version to $VERSION"
98+
git push origin release --force
99+
100+
- name: Create Pull Request
101+
env:
102+
GITHUB_TOKEN: ${{ secrets.TOKEN }}
103+
run: |
104+
git push origin release
105+
gh pr create --base main --head release --title "build(release): bump version to ${{ github.event.inputs.version }}" --body "Bump version to ${{ github.event.inputs.version }}"
106+
107+
- name: Output Run ID
108+
run: echo "RUN_ID=${{ github.run_id }}" >> $GITHUB_OUTPUT
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
# From https://github.com/MetaCubeX/mihomo/blob/82517e6ba8059339287911af899ffdffca6a4044/.github/genReleaseNote.sh
3+
4+
while getopts "v:" opt; do
5+
case $opt in
6+
v)
7+
version_range=$OPTARG
8+
;;
9+
\?)
10+
echo "Invalid option: -$OPTARG" >&2
11+
exit 1
12+
;;
13+
esac
14+
done
15+
16+
if [ -z "$version_range" ]; then
17+
echo "Please provide the version range using -v option. Example: chmod +x genReleaseNote.sh && ./genReleaseNote.sh -v 1.0.0..HEAD" >&2
18+
exit 1
19+
fi
20+
21+
repo_url=$(git config --get remote.origin.url)
22+
if [ -z "$repo_url" ]; then
23+
echo "Could not determine the repository URL. Please ensure you are in a git repository." >&2
24+
exit 1
25+
fi
26+
27+
repo_url=${repo_url%.git}
28+
29+
new_commits=$(git log --pretty=format:"* %h %s by @%an" --grep="^feat" -i $version_range | sort -f | uniq)
30+
if [ -n "$new_commits" ]; then
31+
echo "## New" >> release.md
32+
echo "$new_commits" >> release.md
33+
echo "" >> release.md
34+
fi
35+
36+
fix_commits=$(git log --pretty=format:"* %h %s by @%an" --grep="^fix" -i $version_range | sort -f | uniq)
37+
if [ -n "$fix_commits" ]; then
38+
echo "## Fix" >> release.md
39+
echo "$fix_commits" >> release.md
40+
echo "" >> release.md
41+
fi
42+
43+
maint_commits=$(git log --pretty=format:"* %h %s by @%an" --grep="^chore\|^docs\|^refactor" -i $version_range | sort -f | uniq)
44+
if [ -n "$maint_commits" ]; then
45+
echo "## Maintenance" >> release.md
46+
echo "$maint_commits" >> release.md
47+
echo "" >> release.md
48+
fi
49+
50+
echo "**Full Changelog**: $repo_url/compare/$version_range" >> release.md

.github/workflows/release.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'src/version.h'
9+
10+
jobs:
11+
release:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
with:
18+
ref: main
19+
fetch-depth: 0
20+
21+
- name: Get Last Tag
22+
run: |
23+
LAST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1) || echo "0.0.0")
24+
echo "LAST_TAG=$LAST_TAG" >> $GITHUB_ENV
25+
26+
- name: Get Version from version.h
27+
run: |
28+
MAJOR=$(grep '#define RELEASE_VER_MAIN' src/version.h | awk '{print $3}')
29+
MINOR=$(grep '#define RELEASE_VER_SUB' src/version.h | awk '{print $3}')
30+
PATCH=$(grep '#define RELEASE_VER_FIX' src/version.h | awk '{print $3}')
31+
VERSION="$MAJOR.$MINOR.$PATCH"
32+
echo "VERSION=$VERSION" >> $GITHUB_ENV
33+
34+
- name: Create Tag
35+
run: |
36+
git config user.name "github-actions[bot]"
37+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
38+
git tag -a "${{ env.VERSION }}" -m "${{ env.VERSION }}"
39+
40+
- name: Generate Release Notes
41+
run: |
42+
chmod +x .github/workflows/genReleaseNote.sh
43+
.github/workflows/genReleaseNote.sh -v ${{ env.LAST_TAG }}...${{ env.VERSION }}
44+
45+
- name: Get Latest Workflow Run
46+
id: workflow
47+
run: |
48+
RUN_ID=$(gh api repos/${{ github.repository }}/actions/workflows/build.yml/runs \
49+
--jq '.workflow_runs[0].id')
50+
echo "run_id=$RUN_ID" >> $GITHUB_OUTPUT
51+
env:
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
54+
- name: Download Build Artifacts
55+
uses: actions/download-artifact@v4
56+
with:
57+
path: build_artifacts
58+
github-token: ${{ secrets.GITHUB_TOKEN }}
59+
run-id: ${{ steps.workflow.outputs.run_id }}
60+
61+
- name: Prepare Release Files
62+
run: |
63+
for arch in x86 x64 arm64; do
64+
mv build_artifacts/setdll-$arch/setdll.exe build_artifacts/setdll-$arch.exe
65+
done
66+
cp injectpe.bat build_artifacts/
67+
cp README.md build_artifacts/
68+
69+
- name: Create Archive
70+
run: |
71+
cd build_artifacts
72+
7z a -mx=9 -ms=on -m0=lzma2 -mmt=on setdll-${{ env.VERSION }}.7z *
73+
74+
- name: Create Release
75+
uses: softprops/action-gh-release@v1
76+
with:
77+
tag_name: ${{ env.VERSION }}
78+
name: ${{ env.VERSION }}
79+
body_path: release.md
80+
files: build_artifacts/setdll-${{ env.VERSION }}.7z
81+
env:
82+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

src/setdll.rc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <windows.h>
2+
#include "version.h"
3+
4+
VS_VERSION_INFO VERSIONINFO
5+
FILEVERSION RELEASE_VER_MAIN,RELEASE_VER_SUB,RELEASE_VER_FIX,0
6+
PRODUCTVERSION RELEASE_VER_MAIN,RELEASE_VER_SUB,RELEASE_VER_FIX,0
7+
FILEFLAGSMASK 0x3fL
8+
FILEFLAGS 0x0L
9+
FILEOS 0x40004L
10+
FILETYPE 0x2L
11+
FILESUBTYPE 0x0L
12+
BEGIN
13+
BLOCK "StringFileInfo"
14+
BEGIN
15+
BLOCK "080404b0"
16+
BEGIN
17+
VALUE "FileDescription", "https://github.com/Bush2021/setdll"
18+
VALUE "FileVersion", RELEASE_VER_STR
19+
VALUE "InternalName", "setdll.exe"
20+
VALUE "LegalCopyright", "GPL-3.0 License"
21+
VALUE "OriginalFilename", "setdll.exe"
22+
VALUE "ProductName", "setdll"
23+
VALUE "ProductVersion", RELEASE_VER_STR
24+
END
25+
END
26+
BLOCK "VarFileInfo"
27+
BEGIN
28+
VALUE "Translation", 0x804, 1200
29+
END
30+
END

src/version.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef VERSION_H_
2+
#define VERSION_H_
3+
4+
#define RELEASE_VER_MAIN 1
5+
#define RELEASE_VER_SUB 0
6+
#define RELEASE_VER_FIX 0
7+
8+
#define TOSTRING2(arg) #arg
9+
#define TOSTRING(arg) TOSTRING2(arg)
10+
11+
#define RELEASE_VER_STR \
12+
TOSTRING(RELEASE_VER_MAIN) \
13+
"." TOSTRING(RELEASE_VER_SUB) "." TOSTRING(RELEASE_VER_FIX)
14+
15+
#endif // VERSION_H_

xmake.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ target("setdll")
2525
set_targetdir("$(buildir)/release")
2626
add_deps("detours")
2727
add_links("detours")
28-
add_files("src/*.cpp")
28+
add_files("src/*.cpp")
29+
add_files("src/*.rc")

0 commit comments

Comments
 (0)