diff --git a/.github/workflows/update-built-in-talk.yml b/.github/workflows/update-built-in-talk.yml new file mode 100644 index 00000000..fd09216d --- /dev/null +++ b/.github/workflows/update-built-in-talk.yml @@ -0,0 +1,51 @@ +# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: CC0-1.0 + +name: Update Built-in Talk + +permissions: + contents: write + pull-requests: write + +on: + workflow_dispatch: + +jobs: + update-built-in-talk: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup node + uses: actions/setup-node@v4 + + - name: Run update-built-in-talk.mjs + id: update + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Execute the script and capture the output + stdout=$(npx -y zx ./scripts/update-built-in-talk.mjs) + # Pass the result to the next steps + echo "stdout<> $GITHUB_OUTPUT + echo "$stdout" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + - name: Print result + run: echo "${{ steps.update.outputs.stdout }}" + + - name: Create Pull Request + if: steps.update.outcome == 'success' + uses: peter-evans/create-pull-request@v7 + with: + commit-message: 'build: update built-in Talk version' + signoff: true + branch: 'build/update-built-in-talk-version' + delete-branch: true + title: 'build: update built-in Talk versions' + body: | + ## Update Built-in Talk Version + + ${{ steps.update.outputs.stdout }} diff --git a/scripts/semver.utils.mjs b/scripts/semver.utils.mjs new file mode 100644 index 00000000..9fe27882 --- /dev/null +++ b/scripts/semver.utils.mjs @@ -0,0 +1,24 @@ +/* + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +/** + * Is version A greater than version B? + * @param {string} versionA - Version A + * @param {string} versionB - Version B + * @return {boolean} - Whether version A greater than version B + */ +export function semverGt(versionA, versionB) { + const parse = (v) => [...v.split('-')[0].split('.').map((v) => parseInt(v)), v.split('-')[1] || 'z'] + const a = parse(versionA) + const b = parse(versionB) + for (let i = 0; i < a.length; i++) { + if (a[i] > b[i]) { + return true + } else if (a[i] < b[i]) { + return false + } + } + return false +} diff --git a/scripts/update-built-in-talk.mjs b/scripts/update-built-in-talk.mjs new file mode 100644 index 00000000..a6dfa425 --- /dev/null +++ b/scripts/update-built-in-talk.mjs @@ -0,0 +1,47 @@ +/* + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import { semverGt } from './semver.utils.mjs' + +if (os.platform() === 'win32') { + usePwsh() +} + +// Verify that GitHub CLI is available and authenticated +await $`gh auth status` + +// Read the current version +const packageJsonPath = path.join(__dirname, '../package.json') +const packageJson = await fs.readJson(packageJsonPath) + +const currentBeta = packageJson.talk.beta +const currentStable = packageJson.talk.stable + +// Check the latest releases +const latestStable = (await $`gh release list -R nextcloud-releases/spreed --json tagName --limit=1 --exclude-drafts --exclude-pre-releases`.json())[0].tagName +const latestBeta = (await $`gh release list -R nextcloud-releases/spreed --json tagName --limit=1 --exclude-drafts`.json())[0].tagName + +echo`Stable:` +echo`- Current: ${currentStable}` +echo`- Latest: ${latestStable}` +echo`` +echo`Beta:` +echo`- Current: ${currentBeta}` +echo`- Latest: ${latestBeta}` +echo`` + +// Update the version if necessary +if (semverGt(latestStable, currentStable)) { + echo`Updating stable from ${currentStable} to ${latestStable}` + packageJson.talk.stable = latestStable +} + +if (semverGt(latestBeta, currentBeta)) { + echo`Updating beta from ${currentBeta} to ${latestBeta}` + packageJson.talk.beta = latestBeta +} + +// Write package.json +await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 })