A local-first personal finance app
merge automatic package versioning GitHub workflows (#5480)
Matt Fiddamand98e8375a856
diff --git a/.github/actions/bump-package-versions b/.github/actions/bump-package-versionsdeleted file mode 100755index a9dc9e8932..0000000000--- a/.github/actions/bump-package-versions+++ /dev/null@@ -1,53 +0,0 @@-#!/bin/bash-set -euo pipefail--if [ "$#" -gt 0 ]; then- version="${1#v}"-else- version=""-fi--files_to_bump=(- packages/api/package.json- packages/desktop-client/package.json- packages/desktop-electron/package.json- packages/sync-server/package.json-)--for file in "${files_to_bump[@]}"; do- if [ -z "$version" ]; then- # version format: YY.MM.patch- version="$(jq -r .version "$file" | perl -e '- ($y,$m,$p)=split(/\./,<>);- ($sec,$min,$hour,$day,$mon,$year)=localtime();- $year -= 100; # Perl year starts at 1900- $mon++; # Adjust 0-indexed month to 1-indexed- if ($y == $year && $m == $mon) {- if ($day <= 25) {- # Patch release for the current month- $p++;- } else {- # Use next month for a new release period- $p = 0;- $m++;- $m > 12 && ($m=1, $y++);- }- } else {- # Use the current date for a new release period- $y = $year;- $m = $mon;- $p = 0;- }- print "$y.$m.$p\n";- ')"-- if [ -z "$version" ]; then- echo "Error: Failed to calculate new version" >&2- exit 1- fi- fi-- echo "Bumping $file to version $version"- jq '.version = "'"$version"'"' "$file" > "$file.tmp"- mv "$file.tmp" "$file"-donediff --git a/.github/actions/get-next-package-version.js b/.github/actions/get-next-package-version.jsindex 4b52b35668..16e22f7880 100644--- a/.github/actions/get-next-package-version.js+++ b/.github/actions/get-next-package-version.js@@ -14,9 +14,14 @@ const options = {short: 'p',},type: {- type: 'string', // nightly, hotfix, monthly+ type: 'string', // nightly, hotfix, monthly, autoshort: 't',},+ update: {+ type: 'boolean',+ short: 'u',+ default: false,+ },};const { values } = parseArgs({@@ -57,37 +62,55 @@ try {const nextVersionYear = nextVersionMonthDate.getFullYear().toString()- .slice(-2);+ .slice(nextVersionMonthDate.getFullYear() < 2100 ? -2 : -3);const nextVersionMonth = nextVersionMonthDate.getMonth() + 1; // Convert back to 1-indexed// Get current date string- const currentDate = new Date()+ const currentDate = new Date();+ const currentDateString = currentDate.toISOString().split('T')[0].replaceAll('-', '');+ if (values.type === 'auto') {+ if (currentDate.getDate() <= 25) {+ values.type = 'hotfix';+ } else {+ values.type = 'monthly';+ }+ }++ let newVersion;switch (values.type) {case 'nightly': {- const newVersion = `${nextVersionYear}.${nextVersionMonth}.0-nightly.${currentDate}`;- process.stdout.write(newVersion); // return the new version to stdout- process.exit();+ newVersion = `${nextVersionYear}.${nextVersionMonth}.0-nightly.${currentDateString}`;+ break;}case 'hotfix': {- const bugfixVersion = `${versionYear}.${versionMonth}.${versionHotfix + 1}`;- process.stdout.write(bugfixVersion); // return the bugfix version to stdout- process.exit();+ newVersion = `${versionYear}.${versionMonth}.${versionHotfix + 1}`;+ break;}case 'monthly': {- const stableVersion = `${nextVersionYear}.${nextVersionMonth}.0`;- process.stdout.write(stableVersion); // return the stable version to stdout- process.exit();+ newVersion = `${nextVersionYear}.${nextVersionMonth}.0`;+ break;}default:console.error(- 'Invalid type specified. Use "nightly", "hotfix", or "monthly".',+ 'Invalid type specified. Use "auto", "nightly", "hotfix", or "monthly".',);process.exit(1);}++ process.stdout.write(newVersion); // return the new version to stdout++ if (values.update) {+ packageJson.version = newVersion;+ fs.writeFileSync(+ packageJsonPath,+ JSON.stringify(packageJson, null, 2) + '\n',+ 'utf8',+ );+ }} catch (error) {console.error('Error:', error.message);process.exit(1);diff --git a/.github/workflows/generate-release-pr.yml b/.github/workflows/generate-release-pr.ymlindex 4665f4690d..dd59d2f746 100644--- a/.github/workflows/generate-release-pr.yml+++ b/.github/workflows/generate-release-pr.yml@@ -24,8 +24,29 @@ jobs:id: bump_package_versionsshell: bashrun: |- .github/actions/bump-package-versions ${{ github.event.inputs.version }}- echo "version=$(jq -r .version packages/desktop-client/package.json)" > $GITHUB_OUTPUT+ declare -A packages=(+ [web]="desktop-client"+ [electron]="desktop-electron"+ [sync]="sync-server"+ [api]="api"+ )++ for key in "${!packages[@]}"; do+ pkg="${packages[$key]}"++ if [[ -n "${{ github.event.inputs.version }}" ]]; then+ version="${{ github.event.inputs.version }}"+ else+ version=$(node ./.github/actions/get-next-package-version.js \+ --package-json "./packages/$pkg/package.json" \+ --type auto+ --update)+ fi++ eval "NEW_${key^^}_VERSION=\"$version\""+ done++ echo "version=$NEW_WEB_VERSION" >> "$GITHUB_OUTPUT"- name: Create PRuses: peter-evans/create-pull-request@v7with:diff --git a/upcoming-release-notes/5480.md b/upcoming-release-notes/5480.mdnew file mode 100644index 0000000000..3cd30bc388--- /dev/null+++ b/upcoming-release-notes/5480.md@@ -0,0 +1,6 @@+---+category: Maintenance+authors: [matt-fidd]+---++Merge automatic package versioning GitHub workflows