From ba6d41f5da7f5b7bf4b803096183dc1ff2cbdd03 Mon Sep 17 00:00:00 2001 From: Jens Geudens Date: Fri, 24 Apr 2026 23:35:28 +0200 Subject: [PATCH 1/5] Add automated version update script and workflow --- .github/workflows/update-version.yml | 69 ++++++++++++++++++++++++++++ scripts/update_version.sh | 31 +++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 .github/workflows/update-version.yml create mode 100644 scripts/update_version.sh diff --git a/.github/workflows/update-version.yml b/.github/workflows/update-version.yml new file mode 100644 index 0000000..a3f2d55 --- /dev/null +++ b/.github/workflows/update-version.yml @@ -0,0 +1,69 @@ +name: Update version + +on: + schedule: + - cron: '0 6 * * *' + workflow_dispatch: + +jobs: + update-version: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Fetch latest release + id: release + env: + GH_TOKEN: ${{ github.token }} + run: | + release=$(gh api repos/ModbusScope/ModbusScope/releases/latest) + tag=$(echo "$release" | jq -r '.tag_name') + html_url=$(echo "$release" | jq -r '.html_url') + published_at=$(echo "$release" | jq -r '.published_at') + echo "tag=$tag" >> "$GITHUB_OUTPUT" + echo "html_url=$html_url" >> "$GITHUB_OUTPUT" + echo "published_at=$published_at" >> "$GITHUB_OUTPUT" + + - name: Check if update is needed + id: check + run: | + current=$(jq -r '.tag_name' updater/version.json) + if [ "$current" != "${{ steps.release.outputs.tag }}" ]; then + echo "needs_update=true" >> "$GITHUB_OUTPUT" + else + echo "needs_update=false" >> "$GITHUB_OUTPUT" + fi + + - name: Run update script + if: steps.check.outputs.needs_update == 'true' + run: | + chmod +x scripts/update_version.sh + ./scripts/update_version.sh \ + "${{ steps.release.outputs.tag }}" \ + "${{ steps.release.outputs.html_url }}" \ + "${{ steps.release.outputs.published_at }}" + + - name: Commit and open pull request + if: steps.check.outputs.needs_update == 'true' + env: + GH_TOKEN: ${{ github.token }} + run: | + new_tag="${{ steps.release.outputs.tag }}" + branch="update-version-${new_tag}" + + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git checkout -b "$branch" + git add updater/version.json index.html + git commit -m "Update version to ${new_tag}" + git push -u origin "$branch" + + gh pr create \ + --title "Update version to ${new_tag}" \ + --body "Automated update: bumps all version references and \`updater/version.json\` to [${new_tag}](${{ steps.release.outputs.html_url }})." \ + --base main \ + --head "$branch" diff --git a/scripts/update_version.sh b/scripts/update_version.sh new file mode 100644 index 0000000..cf81ebd --- /dev/null +++ b/scripts/update_version.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +set -euo pipefail + +TAG_NAME="$1" +HTML_URL="$2" +PUBLISHED_AT="$3" + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" + +# Update updater/version.json +jq \ + --arg tag "$TAG_NAME" \ + --arg url "$HTML_URL" \ + --arg date "$PUBLISHED_AT" \ + '.tag_name = $tag | .html_url = $url | .published_at = $date' \ + "$REPO_ROOT/updater/version.json" > "$REPO_ROOT/updater/version.json.tmp" +mv "$REPO_ROOT/updater/version.json.tmp" "$REPO_ROOT/updater/version.json" + +# Derive "Month YYYY" for footer +MONTH_YEAR=$(date -d "$PUBLISHED_AT" '+%B %Y') + +# Update "Download vX.Y.Z" (two occurrences in index.html) +sed -i "s/Download v[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*/Download v${TAG_NAME}/g" \ + "$REPO_ROOT/index.html" + +# Update footer: "Latest release: vX.Y.Z (Month YYYY)" +sed -i "s/Latest release: v[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]* ([^)]*)/Latest release: v${TAG_NAME} (${MONTH_YEAR})/g" \ + "$REPO_ROOT/index.html" + +echo "Updated to ${TAG_NAME}" From 54a0976ae6a5fa912f67e1997ad660065098dc23 Mon Sep 17 00:00:00 2001 From: Jens Geudens Date: Wed, 29 Apr 2026 21:27:15 +0200 Subject: [PATCH 2/5] Update more versions --- scripts/update_version.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/update_version.sh b/scripts/update_version.sh index cf81ebd..0ed6869 100644 --- a/scripts/update_version.sh +++ b/scripts/update_version.sh @@ -28,4 +28,8 @@ sed -i "s/Download v[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*/Download v${TAG_NAME}/ sed -i "s/Latest release: v[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]* ([^)]*)/Latest release: v${TAG_NAME} (${MONTH_YEAR})/g" \ "$REPO_ROOT/index.html" +# Update softwareVersion in JSON-LD structured data +sed -i "s/\"softwareVersion\": \"[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\"/\"softwareVersion\": \"${TAG_NAME}\"/g" \ + "$REPO_ROOT/index.html" + echo "Updated to ${TAG_NAME}" From 37b76489fb5abae4e9f5e5539fb40521bdb4c41c Mon Sep 17 00:00:00 2001 From: Jens Geudens Date: Wed, 29 Apr 2026 21:33:10 +0200 Subject: [PATCH 3/5] Simplify script --- scripts/update_version.sh | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/scripts/update_version.sh b/scripts/update_version.sh index 0ed6869..974ee1e 100644 --- a/scripts/update_version.sh +++ b/scripts/update_version.sh @@ -20,16 +20,12 @@ mv "$REPO_ROOT/updater/version.json.tmp" "$REPO_ROOT/updater/version.json" # Derive "Month YYYY" for footer MONTH_YEAR=$(date -d "$PUBLISHED_AT" '+%B %Y') -# Update "Download vX.Y.Z" (two occurrences in index.html) -sed -i "s/Download v[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*/Download v${TAG_NAME}/g" \ +# Replace all X.Y.Z version occurrences in index.html +sed -i "s/[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*/${TAG_NAME}/g" \ "$REPO_ROOT/index.html" -# Update footer: "Latest release: vX.Y.Z (Month YYYY)" -sed -i "s/Latest release: v[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]* ([^)]*)/Latest release: v${TAG_NAME} (${MONTH_YEAR})/g" \ - "$REPO_ROOT/index.html" - -# Update softwareVersion in JSON-LD structured data -sed -i "s/\"softwareVersion\": \"[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\"/\"softwareVersion\": \"${TAG_NAME}\"/g" \ +# Update the month/year suffix in the footer release line +sed -i "s/Latest release: v${TAG_NAME} ([^)]*)/Latest release: v${TAG_NAME} (${MONTH_YEAR})/g" \ "$REPO_ROOT/index.html" echo "Updated to ${TAG_NAME}" From 632d8ef25393655fd92df3b7281d3224a60007a7 Mon Sep 17 00:00:00 2001 From: Jens Geudens Date: Wed, 29 Apr 2026 21:37:40 +0200 Subject: [PATCH 4/5] Make script executable --- scripts/update_version.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/update_version.sh diff --git a/scripts/update_version.sh b/scripts/update_version.sh old mode 100644 new mode 100755 From c185db72cb39ac26929506053640524f9c81e93b Mon Sep 17 00:00:00 2001 From: Jens Geudens Date: Wed, 29 Apr 2026 21:45:10 +0200 Subject: [PATCH 5/5] Let script retrieve latest release --- .github/workflows/update-version.yml | 26 ++++++-------------------- scripts/update_version.sh | 9 +++++---- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/.github/workflows/update-version.yml b/.github/workflows/update-version.yml index a3f2d55..465db65 100644 --- a/.github/workflows/update-version.yml +++ b/.github/workflows/update-version.yml @@ -15,24 +15,12 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Fetch latest release - id: release - env: - GH_TOKEN: ${{ github.token }} - run: | - release=$(gh api repos/ModbusScope/ModbusScope/releases/latest) - tag=$(echo "$release" | jq -r '.tag_name') - html_url=$(echo "$release" | jq -r '.html_url') - published_at=$(echo "$release" | jq -r '.published_at') - echo "tag=$tag" >> "$GITHUB_OUTPUT" - echo "html_url=$html_url" >> "$GITHUB_OUTPUT" - echo "published_at=$published_at" >> "$GITHUB_OUTPUT" - - name: Check if update is needed id: check run: | current=$(jq -r '.tag_name' updater/version.json) - if [ "$current" != "${{ steps.release.outputs.tag }}" ]; then + latest=$(curl -fsSL https://api.github.com/repos/ModbusScope/ModbusScope/releases/latest | jq -r '.tag_name') + if [ "$current" != "$latest" ]; then echo "needs_update=true" >> "$GITHUB_OUTPUT" else echo "needs_update=false" >> "$GITHUB_OUTPUT" @@ -42,17 +30,15 @@ jobs: if: steps.check.outputs.needs_update == 'true' run: | chmod +x scripts/update_version.sh - ./scripts/update_version.sh \ - "${{ steps.release.outputs.tag }}" \ - "${{ steps.release.outputs.html_url }}" \ - "${{ steps.release.outputs.published_at }}" + ./scripts/update_version.sh - name: Commit and open pull request if: steps.check.outputs.needs_update == 'true' env: GH_TOKEN: ${{ github.token }} run: | - new_tag="${{ steps.release.outputs.tag }}" + new_tag=$(jq -r '.tag_name' updater/version.json) + html_url=$(jq -r '.html_url' updater/version.json) branch="update-version-${new_tag}" git config user.name "github-actions[bot]" @@ -64,6 +50,6 @@ jobs: gh pr create \ --title "Update version to ${new_tag}" \ - --body "Automated update: bumps all version references and \`updater/version.json\` to [${new_tag}](${{ steps.release.outputs.html_url }})." \ + --body "Automated update: bumps all version references and \`updater/version.json\` to [${new_tag}](${html_url})." \ --base main \ --head "$branch" diff --git a/scripts/update_version.sh b/scripts/update_version.sh index 974ee1e..6865d9b 100755 --- a/scripts/update_version.sh +++ b/scripts/update_version.sh @@ -1,13 +1,14 @@ #!/usr/bin/env bash set -euo pipefail -TAG_NAME="$1" -HTML_URL="$2" -PUBLISHED_AT="$3" - SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" +RELEASE=$(curl -fsSL https://api.github.com/repos/ModbusScope/ModbusScope/releases/latest) +TAG_NAME=$(echo "$RELEASE" | jq -r '.tag_name') +HTML_URL=$(echo "$RELEASE" | jq -r '.html_url') +PUBLISHED_AT=$(echo "$RELEASE" | jq -r '.published_at') + # Update updater/version.json jq \ --arg tag "$TAG_NAME" \