From d048141f64fa29852dc7e9a2cdb4b048c509f43f Mon Sep 17 00:00:00 2001 From: FabianLars Date: Tue, 3 Dec 2024 14:44:18 +0100 Subject: [PATCH] ci: Force the same version bumps for rs and js packages --- .changes/bad.md | 5 ++ .changes/badtoo.md | 5 ++ .changes/good.md | 6 ++ .changes/readme.md | 2 + .github/workflows/check-change-files.yml | 44 +++++++++++++ .scripts/ci/check-change-files.js | 84 ++++++++++++++++++++++++ 6 files changed, 146 insertions(+) create mode 100644 .changes/bad.md create mode 100644 .changes/badtoo.md create mode 100644 .changes/good.md create mode 100644 .github/workflows/check-change-files.yml create mode 100644 .scripts/ci/check-change-files.js diff --git a/.changes/bad.md b/.changes/bad.md new file mode 100644 index 00000000..7510ba56 --- /dev/null +++ b/.changes/bad.md @@ -0,0 +1,5 @@ +--- +upload: patch +--- + +test \ No newline at end of file diff --git a/.changes/badtoo.md b/.changes/badtoo.md new file mode 100644 index 00000000..fb18834d --- /dev/null +++ b/.changes/badtoo.md @@ -0,0 +1,5 @@ +--- +upload-js: patch +--- + +test \ No newline at end of file diff --git a/.changes/good.md b/.changes/good.md new file mode 100644 index 00000000..e1830eb3 --- /dev/null +++ b/.changes/good.md @@ -0,0 +1,6 @@ +--- +upload: patch +upload-js: patch +--- + +test \ No newline at end of file diff --git a/.changes/readme.md b/.changes/readme.md index 96cb9f77..6d9396ba 100644 --- a/.changes/readme.md +++ b/.changes/readme.md @@ -6,6 +6,8 @@ As you create PRs and make changes that require a version bump, please add a new When you select the version bump required, you do _not_ need to consider dependencies. Only note the package with the actual change, and any packages that depend on that package will be bumped automatically in the process. +**Note, that in this repository, even if only the Rust code or only the JavaScript code of a plugin changed, both packages need to be bumped with the same increment!** + Use the following format: ```md diff --git a/.github/workflows/check-change-files.yml b/.github/workflows/check-change-files.yml new file mode 100644 index 00000000..40e5c13b --- /dev/null +++ b/.github/workflows/check-change-files.yml @@ -0,0 +1,44 @@ +# Copyright 2019-2024 Tauri Programme within The Commons Conservancy +# SPDX-License-Identifier: Apache-2.0 +# SPDX-License-Identifier: MIT + +name: check change files + +on: + pull_request: + paths: + - '.changes/*.md' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: check change files end with .md + run: | + for file in .changes/* + do + if [[ ! "$file" =~ \.(md|json)$ ]]; then + echo ".changes directory should only contain files that end with .md" + echo "found an invalid file in .changes directory:" + echo "$file" + exit 1 + fi + done + + - uses: dorny/paths-filter@v3 + id: filter + with: + list-files: shell + filters: | + changes: + - added|modified: '.changes/*.md' + + - name: check + run: node ./.scripts/ci/check-change-files.js ${{ steps.filter.outputs.changes_files }} + if: ${{ steps.filter.outputs.changes == 'true' }} diff --git a/.scripts/ci/check-change-files.js b/.scripts/ci/check-change-files.js new file mode 100644 index 00000000..4cf834e7 --- /dev/null +++ b/.scripts/ci/check-change-files.js @@ -0,0 +1,84 @@ +#!/usr/bin/env node + +// Copyright 2019-2024 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +import { readFileSync, readdirSync } from 'fs' +import { join } from 'path' + +const ignorePackages = [ + 'api-example', + 'api-example-js', + 'deep-link-example', + 'deep-link-example-js' +] + +function checkChangeFiles(changeFiles) { + let code = 0 + + for (const file of changeFiles) { + const content = readFileSync(file, 'utf8') + const [frontMatter] = /^---[\s\S.]*---\n/i.exec(content) + const packages = frontMatter + .split('\n') + .filter((l) => !(l === '---' || !l)) + .map((l) => l.replace(/('|")/g, '').split(':')) + + console.log('pkgs', JSON.stringify(packages)) + + const rsPackages = Object.fromEntries( + packages + .filter((v) => !v[0].endsWith('-js')) + .map((v) => [v[0], v[1].trim()]) + ) + const jsPackages = Object.fromEntries( + packages + .filter((v) => v[0].endsWith('-js')) + .map((v) => [v[0].slice(0, -3), v[1].trim()]) + ) + + for (const pkg in rsPackages) { + if (!jsPackages[pkg]) { + console.error( + `Missing "${rsPackages[pkg]}" bump for JS package "${pkg}-js" in ${file}.` + ) + code = 1 + } else if (rsPackages[pkg] != jsPackages[pkg]) { + console.error( + `"${pkg}" and "${pkg}-js" have different version bumps in ${file}.` + ) + code = 1 + } + } + + for (const pkg in jsPackages) { + if (!rsPackages[pkg]) { + console.error( + `Missing "${jsPackages[pkg]}" bump for Rust package "${pkg}" in ${file}.` + ) + code = 1 + } else if (rsPackages[pkg] != jsPackages[pkg]) { + console.error( + `"${pkg}" and "${pkg}-js" have different version bumps in ${file}.` + ) + code = 1 + } + } + } + + process.exit(code) +} + +const [_bin, _script, ...files] = process.argv + +if (files.length > 0) { + checkChangeFiles( + files.filter((f) => f.toLowerCase() !== '.changes/readme.md') + ) +} else { + const changeFiles = readdirSync('.changes') + .filter((f) => f.endsWith('.md') && f.toLowerCase() !== 'readme.md') + .map((p) => join('.changes', p)) + checkChangeFiles(changeFiles) +}