Merge pull request #104 from lpm0073/dependabot/npm_and_yarn/site/can… #41
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
#------------------------------------------------------------------------------ | |
# Lawrence McDaniel - https://lawrencemcdaniel.com | |
# Version Bump and Merge Workflow | |
# | |
# Calculate the next version in the main branch. Compares the raw value of | |
# version.js to the calculated value in setup.py. If they are different, | |
# it will update version.js and push the changes to the main branch. | |
#------------------------------------------------------------------------------ | |
name: Semantic Version Bump (main) | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
set-version-main: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
- name: Cache NPM dependencies | |
uses: actions/cache@v4 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node | |
- name: Setup Node.js environment | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20.9.0" | |
- name: Install npm dev dependencies | |
run: npm install | |
working-directory: ./site | |
- name: Get current version | |
# step 1 | |
# the current version persisted to version.js | |
id: current_version | |
shell: bash | |
run: | | |
echo "CURRENT_VERSION=$(node -p "require('./site/src/shared/version.js').VERSION")" >> $GITHUB_ENV | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT }} | |
- name: Get next version | |
# step 2 | |
# retrieve the the next version based on the logic in setup.py, which | |
# strips the pre-release tag from the current version. | |
id: next_version | |
shell: bash | |
run: | | |
echo "NEXT_VERSION=$(node -e 'const getSemanticVersion = require(\"./site/src/shared/getSemanticVersion.js\"); console.log(getSemanticVersion())')" >> $GITHUB_ENV | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT }} | |
- name: null step | |
id: null_step | |
run: echo "i ensure that NEXT_VERSION is set." | |
- name: Check versions | |
# step 3 | |
# calculate the next version based on a comparison of the current version | |
# to the version calucalated in setup.py. If they are different, then | |
# the version used in setup.py takes precedence. | |
id: check_versions | |
run: | | |
if [ "$CURRENT_VERSION" != "$NEXT_VERSION" ]; then | |
echo "VERSION_CHANGED=true" >> $GITHUB_ENV | |
else | |
echo "VERSION_CHANGED=false" >> $GITHUB_ENV | |
fi | |
env: | |
CURRENT_VERSION: ${{ env.CURRENT_VERSION }} | |
NEXT_VERSION: ${{ env.NEXT_VERSION }} | |
- name: another null step | |
id: another_null_step | |
run: echo "i ensure that CURRENT_VERSION, NEXT_VERSION and VERSION_CHANGED are set." | |
- name: Update version.js | |
# step 4 | |
# if VERSION_CHANGED is true, update version.js and push the changes to the | |
# main branch. | |
if: env.VERSION_CHANGED == 'true' | |
id: update_version | |
run: | | |
echo "export const VERSION = '${{ env.NEXT_VERSION }}'" > ./site/src/shared/version.js | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add ./site/src/shared/version.js | |
git commit -m "chore: [gh] Update version.js to ${{ env.NEXT_VERSION }} [skip ci]" | |
git push https://${{ secrets.PAT }}@github.com/${{ github.repository }}.git HEAD:${{ github.ref }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT }} | |
NEXT_VERSION: ${{ env.NEXT_VERSION }} | |
VERSION_CHANGED: ${{ env.VERSION_CHANGED }} |