Skip to content

Commit 7fa54bd

Browse files
committed
feat: enhance backend and frontend release workflows with app token and cleanup branch automation
1 parent e0fcb34 commit 7fa54bd

File tree

3 files changed

+127
-76
lines changed

3 files changed

+127
-76
lines changed

.github/workflows/backend-release.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
- uses: actions/checkout@v4
2121
with:
2222
fetch-depth: 0
23+
# Use the app token for checkout as well
24+
token: ${{ secrets.APP_INSTALLATION_TOKEN }}
2325

2426
- name: git config
2527
run: |
@@ -36,11 +38,11 @@ jobs:
3638
- name: Install dependencies
3739
run: npm ci
3840

39-
# Now run release-it with the --no-git.requireCleanWorkingDir flag
41+
# Now run release-it with the APP_INSTALLATION_TOKEN
4042
- name: Prepare release
4143
working-directory: services/backend
4244
env:
43-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
GITHUB_TOKEN: ${{ secrets.APP_INSTALLATION_TOKEN }}
4446
run: npm run release -- --ci --verbose --no-git.requireCleanWorkingDir
4547

4648
# Get the version after release-it has run
@@ -87,4 +89,4 @@ jobs:
8789
build-args: |
8890
DEPLOYSTACK_BACKEND_VERSION=${{ steps.package-version.outputs.current-version }}
8991
cache-from: type=gha
90-
cache-to: type=gha,mode=max
92+
cache-to: type=gha,mode=max

.github/workflows/branch-cleanup.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Clean Release Branches
2+
3+
on:
4+
pull_request_target:
5+
types: [closed]
6+
branches:
7+
- main
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
issues: write
13+
14+
jobs:
15+
clean-release-branches:
16+
runs-on: ubuntu-latest
17+
# Only run if the PR is from backend-release or frontend-release branches
18+
if: github.event.pull_request.head.ref == 'backend-release' || github.event.pull_request.head.ref == 'frontend-release'
19+
steps:
20+
- name: Delete release branch
21+
uses: actions/github-script@v7
22+
with:
23+
github-token: ${{ secrets.APP_INSTALLATION_TOKEN }}
24+
script: |
25+
const branchName = context.payload.pull_request.head.ref;
26+
const owner = context.repo.owner;
27+
const repo = context.repo.repo;
28+
29+
console.log(`Attempting to delete branch: ${branchName}`);
30+
31+
try {
32+
// Delete the branch
33+
await github.rest.git.deleteRef({
34+
owner: owner,
35+
repo: repo,
36+
ref: `heads/${branchName}`
37+
});
38+
39+
console.log(`Successfully deleted branch: ${branchName}`);
40+
41+
// Add a comment to the PR about the branch deletion
42+
const status = context.payload.pull_request.merged ? 'merged' : 'closed';
43+
const emoji = context.payload.pull_request.merged ? '✅' : '❌';
44+
45+
await github.rest.issues.createComment({
46+
issue_number: context.payload.pull_request.number,
47+
owner: owner,
48+
repo: repo,
49+
body: `## Release Branch Cleanup ${emoji}\n\nBranch \`${branchName}\` has been automatically deleted after PR was ${status}.`
50+
});
51+
52+
} catch (error) {
53+
console.error(`Error deleting branch ${branchName}:`, error);
54+
55+
// Add a comment about the failure
56+
await github.rest.issues.createComment({
57+
issue_number: context.payload.pull_request.number,
58+
owner: owner,
59+
repo: repo,
60+
body: `## Release Branch Cleanup Failed ⚠️\n\nFailed to automatically delete branch \`${branchName}\`. Manual cleanup may be required.\n\nError: ${error.message}`
61+
});
62+
}

.github/workflows/frontend-release-pr.yml

Lines changed: 60 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ on:
66
type: choice
77
description: Choose release type
88
options:
9-
- auto
109
- patch
1110
- minor
1211
- major
13-
default: auto
12+
default: patch
1413
beta:
1514
type: boolean
1615
description: Prerelease
@@ -19,6 +18,7 @@ on:
1918
permissions:
2019
contents: write
2120
pull-requests: write
21+
issues: write
2222

2323
jobs:
2424
releaseIt:
@@ -30,89 +30,77 @@ jobs:
3030
- uses: actions/checkout@v4
3131
with:
3232
fetch-depth: 0
33-
33+
# Use the app token for checkout as well
34+
token: ${{ secrets.APP_INSTALLATION_TOKEN }}
3435
- name: git config
3536
run: |
3637
git config user.name "${GITHUB_ACTOR}"
3738
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
38-
3939
- name: Setup node
4040
uses: actions/setup-node@v4
4141
with:
4242
node-version: 20
4343
cache: npm
44-
45-
# Clean install to avoid rollup issues with optional dependencies
46-
- name: Install dependencies with clean slate
47-
run: |
48-
rm -rf node_modules package-lock.json || true
49-
npm install
50-
51-
# Determine the next version based on input
52-
- name: Get current version
53-
id: current-version
54-
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
55-
56-
- name: Determine next version
57-
id: next-version
44+
- run: npm ci
45+
- name: Prepare release
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.APP_INSTALLATION_TOKEN }}
48+
TYPE_ARG: ${{ fromJSON('{"patch":"patch", "minor":"minor", "major":"major"}')[github.event.inputs.type] }}
49+
BETA_ARG: ${{ github.event.inputs.beta == 'true' && '--preRelease=beta' || '' }}
50+
run: npm run release -- $TYPE_ARG --ci --verbose --no-git.push --no-git.commit --no-git.tag --no-github $BETA_ARG
51+
- name: get-npm-version
52+
id: package-version
53+
uses: martinbeentjes/npm-get-version-action@main
54+
with:
55+
path: services/frontend
56+
- name: Extract release notes
57+
id: extract-release-notes
5858
run: |
59-
current=${{ steps.current-version.outputs.version }}
60-
IFS='.' read -r -a version_parts <<< "$current"
61-
major=${version_parts[0]}
62-
minor=${version_parts[1]}
63-
patch=${version_parts[2]}
64-
65-
# Determine type of version bump
66-
case "${{ github.event.inputs.type }}" in
67-
major)
68-
new_major=$((major + 1))
69-
new_version="$new_major.0.0"
70-
;;
71-
minor)
72-
new_minor=$((minor + 1))
73-
new_version="$major.$new_minor.0"
74-
;;
75-
patch)
76-
new_patch=$((patch + 1))
77-
new_version="$major.$minor.$new_patch"
78-
;;
79-
auto|*)
80-
# Default to minor
81-
new_minor=$((minor + 1))
82-
new_version="$major.$new_minor.0"
83-
;;
84-
esac
59+
# Get the current version from the package.json in the current working directory
60+
VERSION=$(cat package.json | grep '"version"' | cut -d'"' -f4)
61+
echo "Extracting release notes for version $VERSION"
8562
86-
# Add beta suffix if requested
87-
if [[ "${{ github.event.inputs.beta }}" == "true" ]]; then
88-
new_version="${new_version}-beta.1"
63+
# Extract the changelog section for this version
64+
if [ -f CHANGELOG.md ]; then
65+
# Look for the version header and extract content until the next version or end of file
66+
RELEASE_NOTES=$(awk -v version="$VERSION" '
67+
BEGIN { found=0; content="" }
68+
/^##? [0-9]+\.[0-9]+\.[0-9]+/ {
69+
if (found) exit
70+
if ($0 ~ version) { found=1; next }
71+
}
72+
found && /^##? [0-9]+\.[0-9]+\.[0-9]+/ { exit }
73+
found { content = content $0 "\n" }
74+
END { print content }
75+
' CHANGELOG.md)
76+
77+
# Clean up empty markdown links and remove empty lines
78+
CLEAN_NOTES=$(echo "$RELEASE_NOTES" | sed 's/(\[\]([^)]*))//g' | sed '/^$/d')
79+
80+
# Save to output
81+
echo "release_notes<<EOF" >> $GITHUB_OUTPUT
82+
echo "$CLEAN_NOTES" >> $GITHUB_OUTPUT
83+
echo "EOF" >> $GITHUB_OUTPUT
84+
85+
echo "Release notes extracted:"
86+
echo "$CLEAN_NOTES"
87+
else
88+
echo "No CHANGELOG.md found"
89+
echo "release_notes=" >> $GITHUB_OUTPUT
8990
fi
90-
91-
echo "version=$new_version" >> $GITHUB_OUTPUT
92-
93-
# Create a temporary changelog entry
94-
- name: Generate changelog entry
95-
id: changelog
96-
run: |
97-
echo "# ${{ steps.next-version.outputs.version }} ($(date +%Y-%m-%d))" > CHANGELOG_NEW.md
98-
echo "" >> CHANGELOG_NEW.md
99-
echo "### Features" >> CHANGELOG_NEW.md
100-
echo "* Release version ${{ steps.next-version.outputs.version }}" >> CHANGELOG_NEW.md
101-
echo "" >> CHANGELOG_NEW.md
102-
cat CHANGELOG.md >> CHANGELOG_NEW.md 2>/dev/null || true
103-
cat CHANGELOG_NEW.md > TEMP_CHANGELOG.md
104-
105-
# Create a PR with the version changes
91+
working-directory: services/frontend
10692
- name: Create pull request
10793
uses: peter-evans/create-pull-request@v7
10894
id: cpr
10995
with:
96+
# This is the key change - use the app token
97+
token: ${{ secrets.APP_INSTALLATION_TOKEN }}
11098
branch: frontend-release
11199
delete-branch: true
112-
commit-message: 'chore(frontend): release v${{ steps.next-version.outputs.version }}'
113-
title: '[Frontend Release] v${{ steps.next-version.outputs.version }}'
100+
commit-message: 'chore(frontend): release v${{ steps.package-version.outputs.current-version}}'
101+
title: '[Frontend Release] v${{ steps.package-version.outputs.current-version}}'
114102
body: |
115-
## Frontend Release v${{ steps.next-version.outputs.version }}
103+
## Frontend Release v${{ steps.package-version.outputs.current-version}}
116104
117105
This PR prepares a new frontend release.
118106
@@ -122,25 +110,24 @@ jobs:
122110
123111
The Docker image will be available at:
124112
- `deploystack/frontend:latest`
125-
- `deploystack/frontend:v${{ steps.next-version.outputs.version }}`
113+
- `deploystack/frontend:v${{ steps.package-version.outputs.current-version}}`
126114
127115
### Supported Architectures
128116
- `linux/amd64` (Intel/AMD)
129117
- `linux/arm64` (Apple Silicon, AWS Graviton)
130118
- `linux/arm/v7` (Raspberry Pi, IoT devices)
131119
120+
### Environment Variables
121+
The Docker image will include `DEPLOYSTACK_FRONTEND_VERSION` environment variable set to the current version.
122+
132123
## Release notes:
133-
See attached changelog updates
124+
${{ steps.extract-release-notes.outputs.release_notes }}
134125
labels: |
135126
frontend
136127
release
137128
automated pr
138129
draft: false
139-
add-paths: |
140-
services/frontend/package.json
141-
services/frontend/CHANGELOG.md
142-
143130
- name: Show PR link
144131
if: ${{ steps.cpr.outputs.pull-request-url }}
145132
run: |
146-
echo "Frontend Release v${{ steps.next-version.outputs.version }}' pull request - ${{ steps.cpr.outputs.pull-request-url }}"
133+
echo "Frontend Release v${{ steps.package-version.outputs.current-version}}' pull request - ${{ steps.cpr.outputs.pull-request-url }}"

0 commit comments

Comments
 (0)