Skip to content

Commit bc53ff0

Browse files
committed
ci: improve release process
1 parent bbe20a5 commit bc53ff0

File tree

3 files changed

+78
-4
lines changed

3 files changed

+78
-4
lines changed

.github/workflows/publish.yaml

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,64 @@
22
name: Publish
33
on:
44
push:
5-
tags:
6-
- v*
5+
branches:
6+
- main
7+
permissions:
8+
contents: write
79
jobs:
810
publish:
911
runs-on: ubuntu-latest
1012
environment: Production
1113
steps:
1214
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
1315
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
1418
- uses: actions/setup-node@v4
1519
with:
1620
node-version-file: package.json
1721
registry-url: "https://registry.npmjs.org"
1822
cache: "npm"
23+
- name: Get version
24+
id: get-version
25+
shell: bash
26+
run: |
27+
set +e
28+
29+
VERSION=v$(jq -r '.version' < package.json)
30+
echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT"
31+
- name: Check if version already exists
32+
id: check-version
33+
shell: bash
34+
run: |
35+
set +e
36+
37+
git rev-parse "${{ steps.get-version.outputs.VERSION }}" >/dev/null 2>&1
38+
if [[ $? -eq 0 ]]; then
39+
echo "VERSION_EXISTS=true" >> "$GITHUB_OUTPUT"
40+
else
41+
echo "VERSION_EXISTS=false" >> "$GITHUB_OUTPUT"
42+
fi
1943
- name: Build package
44+
if: steps.check-version.outputs.VERSION_EXISTS == 'false'
2045
run: |
2146
npm ci
2247
npm run build
2348
- name: Publish to NPM
49+
if: steps.check-version.outputs.VERSION_EXISTS == 'false'
2450
run: npm publish
2551
env:
2652
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
27-
- name: Publish Github release
53+
- name: Publish git tag
54+
if: steps.check-version.outputs.VERSION_EXISTS == 'false'
55+
run: |
56+
git config --global user.name 'github-actions[bot]'
57+
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
58+
git tag ${{ steps.get-version.outputs.VERSION }}
59+
git push origin --tags
60+
- name: Publish git release
61+
if: steps.check-version.outputs.VERSION_EXISTS == 'false'
62+
env:
63+
GH_TOKEN: ${{ github.token }}
2864
run: |
29-
gh release create ${{ github.ref }} --title "${{ github.ref }}" --notes "Release ${{ github.ref }}" --generate-notes
65+
gh release create ${{ github.env.VERSION }} --title "${{ github.env.VERSION }}" --generate-notes

.github/workflows/version_bump.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
name: Version Bump
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Version to bump to'
8+
required: true
9+
default: 'patch'
10+
jobs:
11+
bump-version:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-node@v4
17+
with:
18+
node-version-file: package.json
19+
registry-url: "https://registry.npmjs.org"
20+
cache: "npm"
21+
- name: Build package
22+
run: |
23+
npm ci
24+
- name: Bump version
25+
run: |
26+
npm version ${{ github.event.inputs.version }} --no-git-tag-version
27+
- name: Create PR
28+
uses: peter-evans/create-pull-request@v4
29+
with:
30+
title: 'Bump version to ${{ github.event.inputs.version }}'
31+
body: 'Bump version to ${{ github.event.inputs.version }}'
32+
base: main
33+
branch: ci/version-bump-${{ github.event.inputs.version }}
34+
commit-message: 'Bump version to ${{ github.event.inputs.version }}'
35+
author: 'github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>'
36+
committer: 'github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>'
37+
labels: version-bump

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
git-tag-version=false

0 commit comments

Comments
 (0)