Skip to content

Commit cae6729

Browse files
ci: add new workflow (#375)
1 parent 55c68f2 commit cae6729

File tree

4 files changed

+137
-59
lines changed

4 files changed

+137
-59
lines changed

.github/workflows/release.yaml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Release to NPM when a tag is pushed
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
- 'v*.*.*-rc.*'
8+
9+
jobs:
10+
release:
11+
name: Release
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 10
14+
steps:
15+
- name: Check Branch and Tag
16+
run: |
17+
BRANCH=$(git branch -r --contains ${{ github.ref }})
18+
TAG=${{ github.ref_name }}
19+
20+
if [[ $BRANCH =~ origin/main$ ]]; then
21+
if [[ $TAG =~ -rc\. ]]; then
22+
echo "[SKIPPED] Release candidate tags (v*.*.*-rc.*) are only allowed on develop branch"
23+
exit 0
24+
fi
25+
elif [[ $BRANCH =~ origin/develop$ ]]; then
26+
if [[ ! $TAG =~ -rc\. ]]; then
27+
echo "[SKIPPED] Release tags (v*.*.*) are only allowed on main branch. Use release candidate tags (v*.*.*-rc.*)"
28+
exit 1
29+
fi
30+
else
31+
echo "[SKIPPED] Tags can only be pushed from main or develop branches"
32+
exit 1
33+
fi
34+
35+
- name: Checkout 🛎️
36+
uses: actions/checkout@v3
37+
with:
38+
fetch-depth: 0
39+
40+
- name: Setup pnpm 9
41+
uses: pnpm/action-setup@v4
42+
with:
43+
version: 9.3.0
44+
45+
- name: Setup Node.js 18.x
46+
uses: actions/setup-node@v2
47+
with:
48+
node-version: 18.x
49+
50+
- name: Install Dependencies 🔧
51+
run: pnpm install
52+
53+
- name: Build Step 🔧
54+
env:
55+
CI: ""
56+
run: pnpm run ci:build
57+
58+
- name: Create .npmrc
59+
run: |
60+
cat << EOF > "$HOME/.npmrc"
61+
//registry.npmjs.org/:_authToken=$NPM_TOKEN
62+
EOF
63+
env:
64+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
65+
66+
- name: Bump Package Version
67+
run: pnpm run bump-version
68+
working-directory: ./packages/raystack
69+
env:
70+
GIT_REFNAME: ${{ github.ref_name }}
71+
72+
- name: Run Release 🚀
73+
run: pnpm run release:ci
74+
working-directory: ./packages/raystack
75+
env:
76+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
78+
79+
- name: Generate GitHub Release Notes 📓
80+
env:
81+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
82+
run: |
83+
gh release create "$GITHUB_REF_NAME" \
84+
--repo "$GITHUB_REPOSITORY" \
85+
--generate-notes \
86+
--verify-tag

.github/workflows/release.yml

Lines changed: 0 additions & 57 deletions
This file was deleted.

.github/workflows/sync-develop.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Sync develop with main
2+
3+
on:
4+
schedule:
5+
# Runs at 5:00 AM UTC every day
6+
- cron: '0 5 * * *'
7+
8+
# Enable "Run Workflow" button to trigger the workflow manually
9+
workflow_dispatch:
10+
11+
jobs:
12+
sync-develop:
13+
name: Sync develop branch with main
14+
runs-on: ubuntu-latest
15+
timeout-minutes: 5
16+
17+
steps:
18+
- name: Checkout 🛎️
19+
uses: actions/checkout@v3
20+
with:
21+
fetch-depth: 0
22+
ref: develop
23+
24+
- name: Configure Git
25+
run: |
26+
git config user.name "GitHub Actions Bot"
27+
git config user.email "github-actions-bot@users.noreply.github.com"
28+
29+
- name: Fetch latest from remote
30+
run: |
31+
git fetch --prune
32+
33+
- name: Merge main into develop
34+
run: |
35+
# Check if main has any changes compared to develop
36+
if git merge-base --is-ancestor origin/main origin/develop; then
37+
echo "[SKIPPED] develop is already up to date with main."
38+
exit 0
39+
fi
40+
41+
# Try to merge main into develop
42+
if git merge origin/main -m "Auto-merge main into develop"; then
43+
echo "[SUCCESS] Successfully merged main into develop"
44+
git push origin develop
45+
else
46+
echo "[MERGE CONFLICT] Manually resolve the merge conflict and push to develop."
47+
git merge --abort
48+
exit 1
49+
fi

packages/raystack/scripts/bump-version.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ async function updatePackageVersion() {
1010
const gitTag = semver.valid(gitRef);
1111
if (gitTag && semver.compare(gitTag, pkg.version) > 0) {
1212
pkg.version = gitTag;
13-
console.log('Updating Version version to', gitTag)
13+
console.log('Bumped version to', gitTag)
1414
await fs.writeFile(path.join(process.cwd(), 'package.json'), JSON.stringify(pkg, null, 2))
1515
}
1616
} catch (err) {
17-
console.error("Update Package Version", err)
17+
console.error("Update Package Version error: ", err)
1818
}
1919
}
2020

0 commit comments

Comments
 (0)