Skip to content

Commit 8dc3361

Browse files
committed
feat: create release
1 parent a07f3a8 commit 8dc3361

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

.github/workflows/release.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: release
2+
on:
3+
push:
4+
branches: [ main ]
5+
6+
permissions:
7+
contents: write
8+
pull-requests: write
9+
10+
jobs:
11+
bump-version:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Check for existing release PR
17+
id: check_pr
18+
run: |
19+
PR_COUNT=$(gh pr list --label release,automated --json number | jq length)
20+
if [ "$PR_COUNT" -gt "0" ]; then
21+
echo "Release PR already exists, exiting workflow."
22+
echo "release_exists=true" >> $GITHUB_OUTPUT
23+
else
24+
echo "No existing release PR found, proceeding with version bump."
25+
echo "release_exists=false" >> $GITHUB_OUTPUT
26+
fi
27+
env:
28+
GH_TOKEN: ${{ secrets.RELEASE_PR_TOKEN }}
29+
30+
- uses: actions-rust-lang/setup-rust-toolchain@v1
31+
if: steps.check_pr.outputs.release_exists != 'true'
32+
33+
- name: SQLx offline
34+
run: echo "SQLX_OFFLINE=true" > .env
35+
if: steps.check_pr.outputs.release_exists != 'true'
36+
37+
- name: Bump version
38+
if: steps.check_pr.outputs.release_exists != 'true'
39+
run: |
40+
# Get the current version from Cargo.toml
41+
CURRENT_VERSION=$(grep -m 1 'version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/')
42+
echo "Current version: $CURRENT_VERSION"
43+
44+
# Parse the version components
45+
MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1)
46+
MINOR=$(echo $CURRENT_VERSION | cut -d. -f2)
47+
PATCH=$(echo $CURRENT_VERSION | cut -d. -f3)
48+
49+
# Increment the patch version
50+
NEW_PATCH=$((PATCH + 1))
51+
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
52+
echo "New version: $NEW_VERSION"
53+
54+
# Update the version in the Cargo.toml file
55+
sed -i "s/version = \"$CURRENT_VERSION\"/version = \"$NEW_VERSION\"/" Cargo.toml
56+
57+
# Store the versions for later steps
58+
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
59+
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
60+
61+
# Verify the update
62+
grep -m 1 'version = ' Cargo.toml
63+
64+
- name: Check generate lock
65+
if: steps.check_pr.outputs.release_exists != 'true'
66+
run: cargo generate-lockfile
67+
68+
- name: Create Pull Request
69+
if: steps.check_pr.outputs.release_exists != 'true'
70+
uses: peter-evans/create-pull-request@v5
71+
with:
72+
token: ${{ secrets.RELEASE_PR_TOKEN }}
73+
commit-message: "chore(release): v${{ env.NEW_VERSION }}"
74+
title: "chore(release): v${{ env.NEW_VERSION }}"
75+
body: "chore(release): v${{ env.CURRENT_VERSION }} to v${{ env.NEW_VERSION }}"
76+
branch: chore/release-v${{ env.NEW_VERSION }}
77+
base: main
78+
labels: automated,release
79+
delete-branch: true
80+
author: 'dosei-bot <bot@dosei.io>'
81+
committer: 'dosei-bot <bot@dosei.io>'
82+
83+
create-release:
84+
runs-on: ubuntu-latest
85+
steps:
86+
- uses: actions/checkout@v4
87+
88+
- name: Set version and commit message
89+
run: |
90+
VERSION=$(grep -m 1 'version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/')
91+
echo "VERSION=$VERSION" >> $GITHUB_ENV
92+
93+
COMMIT_MSG=$(git log -1 --pretty=format:%s)
94+
echo "COMMIT_MSG=$COMMIT_MSG" >> $GITHUB_ENV
95+
96+
- name: Create GitHub Release
97+
if: |
98+
startsWith(env.COMMIT_MSG, format('chore(release): v', env.VERSION))
99+
uses: softprops/action-gh-release@v2
100+
with:
101+
tag_name: v${{ env.VERSION }}
102+
generate_release_notes: true
103+
make_latest: true
104+
env:
105+
GITHUB_TOKEN: ${{ secrets.RELEASE_PR_TOKEN }}

0 commit comments

Comments
 (0)