Skip to content

Commit 5ecaa32

Browse files
committed
Add create-tag and update-v2-tag scripts; enhance GitHub workflows for versioning and auto-deploy
1 parent 3ffcde8 commit 5ecaa32

File tree

4 files changed

+98
-5
lines changed

4 files changed

+98
-5
lines changed

.github/workflows/bump-gitstream-core.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,22 @@ on:
66
workflow_dispatch:
77
inputs:
88
version:
9-
description: Version number (ex. "2.1.20")
9+
description: Version number (ex. "2.1.133")
1010
required: true
11-
default: 2.1.20
11+
default: 2.1.133
1212
ticket:
1313
description: LINBEE-XXXX ticket number
1414
default: LINBEE-8514
1515
required: false
1616
description:
1717
description: Add a description for this version
1818
required: false
19+
auto-deploy:
20+
description: Add label "auto-deploy" to PR
21+
required: false
22+
type: boolean
23+
default: true
24+
1925
jobs:
2026
publish_pr:
2127
name: Publish PR
@@ -27,6 +33,12 @@ jobs:
2733
run: |
2834
echo "VERSION=${{ inputs.version }}" >> "$GITHUB_ENV"
2935
echo "BRANCH_NAME=${{ inputs.ticket }}-bump-gitstream-core-to-${{ inputs.version }}" >> "$GITHUB_ENV"
36+
echo "LABEL_ARG=" >> "$GITHUB_ENV"
37+
38+
- name: Set auto-deploy label
39+
if: inputs.auto-deploy
40+
run: |
41+
echo "LABEL_ARG=--label auto-deploy" >> "$GITHUB_ENV"
3042
3143
- name: Init npmrc
3244
run: |
@@ -53,4 +65,4 @@ jobs:
5365
--title "Bump \`@linearb/gitstream-core\` to \`${{ env.VERSION }}\`" \
5466
--body-file pr_description.txt \
5567
--head ${{ env.BRANCH_NAME }} \
56-
--reviewer ${{ github.actor }}
68+
--reviewer ${{ github.actor }} ${{ env.LABEL_ARG }}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Create Tag on merge
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- develop
8+
paths:
9+
- src/**
10+
- dist/**
11+
- package*.json
12+
13+
jobs:
14+
create-tag:
15+
runs-on: ubuntu-24.04
16+
timeout-minutes: 15
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: actions/setup-node@v4
21+
with:
22+
node-version-file: .nvmrc
23+
24+
- name: Create and push new tag
25+
run: npm run create-tag
26+
27+
- name: Get latest commit
28+
id: get-commit
29+
run: echo "LAST_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV
30+
31+
- name: Check for associated pull request and auto-deploy label
32+
id: should-deploy
33+
uses: actions/github-script@v7
34+
with:
35+
github-token: ${{ secrets.GITHUB_TOKEN }}
36+
script: |
37+
const { owner, repo } = context.repo;
38+
const commit_sha = '${{ env.LAST_SHA }}';
39+
const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ commit_sha, owner, repo });
40+
if (prs?.length > 0) {
41+
const pull_number = prs[0].number;
42+
const { data: pr } = await github.rest.pulls.get({ owner, repo, pull_number });
43+
return pr.labels.some(label => label.name.includes('auto-deploy'));
44+
}
45+
return false;
46+
47+
- name: Create GitHub Release & Deploy
48+
if: steps.should-deploy.outputs.result == 'true'
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
run: |
52+
gh release create $NEW_TAG --generate-notes
53+
git checkout $NEW_TAG
54+
npm run update-v2-tag

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
"lint": "eslint . -c ./.github/linters/.eslintrc.yml",
3232
"package": "ncc build --minify src/index.ts -o dist --license licenses.txt",
3333
"test": "jest",
34-
"all": "npm run format:write && npm run lint && npm run test && npm run package"
34+
"all": "npm run format:write && npm run lint && npm run test && npm run package",
35+
"create-tag": "./scripts/tag-version.sh",
36+
"update-v2-tag": "git tag v2 -f && git push origin v2 -f"
3537
},
3638
"license": "Apache-2.0",
3739
"dependencies": {
@@ -85,4 +87,4 @@
8587
"./src/**"
8688
]
8789
}
88-
}
90+
}

scripts/tag-version.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
git fetch --tags
4+
5+
# Get the latest tag
6+
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`)
7+
8+
# Check if the latest tag starts with 'v' and remove it
9+
if [[ $latest_tag == v* ]]; then
10+
latest_tag=${latest_tag:1}
11+
fi
12+
13+
# Split the latest tag into an array
14+
IFS='.' read -r -a version_parts <<< "$latest_tag"
15+
16+
# Bump the patch version
17+
new_tag="${version_parts[0]}.${version_parts[1]}.$((version_parts[2] + 1))"
18+
19+
# Create and push the new tag
20+
git tag $new_tag
21+
git push origin $new_tag
22+
echo "new_tag=$new_tag"
23+
24+
echo "new_tag=$new_tag" >> $GITHUB_OUTPUT
25+
echo "NEW_TAG=$new_tag" >> $GITHUB_ENV

0 commit comments

Comments
 (0)