Skip to content

chore: automatically increment version in package.json on new release #596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a3e29e0
ci(release): adding a release to automatically increment version in p…
divinecodes Jun 3, 2024
54a7efe
ci(release): add checkout step to release workflow
divinetettey Jun 7, 2024
cae8f79
Merge branch 'main' into 557-auto-increment-version
divinetettey Jun 7, 2024
663e030
Merge branch 'main' into 557-auto-increment-version
divinetettey Jun 11, 2024
bbf6e0f
Merge branch 'main' into 557-auto-increment-version
divinetettey Jun 18, 2024
3e29af9
Merge branch 'main' into 557-auto-increment-version
divinetettey Jun 18, 2024
5f26b95
Merge branch 'main' into 557-auto-increment-version
divinetettey Jun 20, 2024
d6bcfa4
ci(release): move version update to run before releases
divinetettey Jun 20, 2024
778c12f
Update .github/workflows/release.yml
JamieSlome Jun 20, 2024
0be28b9
Merge pull request #1 from divinetettey/557-auto-increment-version
divinetettey Jun 20, 2024
b7b8a11
Revert "557 auto increment version - test"
divinetettey Jun 20, 2024
3cb7cd5
Merge pull request #2 from divinetettey/revert-1-557-auto-increment-v…
divinetettey Jun 20, 2024
499969a
ci(release): improvements to update_version workflow
divinetettey Jun 21, 2024
1027f2e
Merge branch 'main' into 557-auto-increment-version
divinetettey Jun 21, 2024
a69cdde
Merge branch 'main' into 557-auto-increment-version
JamieSlome Jun 22, 2024
c357671
Merge branch 'main' into 557-auto-increment-version
divinetettey Jun 22, 2024
7fbc690
Merge branch 'main' into 557-auto-increment-version
JamieSlome Jul 1, 2024
e4b400d
Merge branch 'main' into 557-auto-increment-version
JamieSlome Jul 1, 2024
3ef3465
Merge branch 'main' into 557-auto-increment-version
divinetettey Jul 4, 2024
111457f
ci(release): add npm install step to release workflow
divinetettey Jul 4, 2024
9d9db92
Merge branch 'main' into 557-auto-increment-version
JamieSlome Oct 2, 2024
6b86691
Merge branch 'main' into 557-auto-increment-version
JamieSlome Oct 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 109 additions & 57 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,112 @@
# ---
# name: Release
---
name: Release

# on:
# workflow_dispatch:
# push:
# branches:
# - main
# paths:
# - 'src/**'
# - 'test/**'
# - 'scripts/**'
# - 'public/**'
# - 'packages/**'
# - 'package.json'
# - 'package-lock.json'
on:
workflow_dispatch:
push:
branches:
- main
paths:
- 'src/**'
- 'test/**'
- 'scripts/**'
- 'public/**'
- 'packages/**'
- 'package.json'
- 'package-lock.json'

# permissions:
# contents: read
permissions:
contents: read

# jobs:
# create_github_release:
# outputs:
# full-tag: ${{ steps.release-drafter.outputs.tag_name }}
# short-tag: ${{ steps.get_tag_name.outputs.SHORT_TAG }}
# body: ${{ steps.release-drafter.outputs.body }}
# runs-on: ubuntu-latest
# permissions:
# contents: write
# pull-requests: read
# steps:
# - uses: release-drafter/release-drafter@v6
# id: release-drafter
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# publish: true
# - name: Get the short tag
# id: get_tag_name
# run: |
# short_tag=$(echo ${{ steps.release-drafter.outputs.tag_name }} | cut -d. -f1)
# echo "SHORT_TAG=$short_tag" >> $GITHUB_OUTPUT
# create_npm_release:
# needs: create_github_release
# runs-on: ubuntu-latest
# permissions:
# packages: write
# env:
# REGISTRY: ghcr.io
# IMAGE_NAME: ${{ github.repository }}
# steps:
# - uses: actions/checkout@8459bc0 # v4
# - uses: actions/setup-node@c2ac33f # v4, Setup .npmrc file to publish to npm
# with:
# node-version: '18.x'
# registry-url: 'https://registry.npmjs.org'
# - run: npm ci
# - run: npm publish --access=public
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
jobs:
update_version:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run Release Drafter
uses: release-drafter/release-drafter@v6
id: release-drafter
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Version
id: extract_version
run: |
version="${{ steps.release-drafter.outputs.tag_name }}"
version=$(echo "$version" || sed 's/^v//')
if [ -z "$version"]; then
echo "Version is empty. Exiting"
exit 1
fi
echo "version=$version" >> $GITHUB_OUTPUT
- name: Update package.json and package-lock.json version
run:
VERSION=${{ steps.extract_version.outputs.version }}
if [ -z "$version"]; then
echo "Version is empty. Exiting"
exit 1
fi
jq --arg version "$VERSION" '.version = $version' package.json > package_tmp.json && mv package_tmp.json package.json
- name: NPM Install
run: npm install
- name: Update docusaurus.config.js version
run: |
VERSION=${{ steps.extract_version.outputs.version }}
if [ -z "$version"]; then
echo "Version is empty. Exiting"
exit 1
fi
sed -i "s/version: '.*'/version: '$VERSION'/" website/docusaurus.config.js
- name: Commit version change
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add package.json package-lock.json website/docusaurus.config.js
Comment on lines +60 to +65

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The echo "$version" || sed 's/^v//' statement is incorrect because echo will always succeed, meaning the sed command after || will never execute. Instead, you should be using | (pipe) instead of ||.

git commit -m "chore: update version to ${{ steps.extract_version.outputs.version }} [skip ci]"

- name: Push Changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
create_github_release:
needs: update_version
outputs:
full-tag: ${{ steps.release-drafter.outputs.tag_name }}
short-tag: ${{ steps.get_tag_name.outputs.SHORT_TAG }}
body: ${{ steps.release-drafter.outputs.body }}
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: read
steps:
- uses: release-drafter/release-drafter@v6
id: release-drafter
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
publish: true
- name: Get the short tag
id: get_tag_name
run: |
short_tag=$(echo ${{ steps.release-drafter.outputs.tag_name }} | cut -d. -f1)
echo "SHORT_TAG=$short_tag" >> $GITHUB_OUTPUT
create_npm_release:
needs: create_github_release
runs-on: ubuntu-latest
permissions:
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
steps:
- uses: actions/checkout@8459bc0 # v4
- uses: actions/setup-node@c2ac33f # v4, Setup .npmrc file to publish to npm
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm publish --access=public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Loading