Skip to content

Commit

Permalink
Merge pull request #1052 from nextcloud/chore/update-built-in-Talk
Browse files Browse the repository at this point in the history
chore: update Build-in Talk script and CI
  • Loading branch information
ShGKme authored Jan 24, 2025
2 parents bd471ba + ce851b6 commit 851ca72
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/update-built-in-talk.yml
Original file line number Diff line number Diff line change
@@ -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<<EOF" >> $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 }}
24 changes: 24 additions & 0 deletions scripts/semver.utils.mjs
Original file line number Diff line number Diff line change
@@ -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
}
47 changes: 47 additions & 0 deletions scripts/update-built-in-talk.mjs
Original file line number Diff line number Diff line change
@@ -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 })

0 comments on commit 851ca72

Please sign in to comment.