Skip to content

Update NATS Tool Versions #229

Update NATS Tool Versions

Update NATS Tool Versions #229

name: Update NATS Tool Versions
on:
schedule:
# Run daily at 14:00 UTC
- cron: "0 14 * * *"
workflow_dispatch:
# Allow manual triggering
permissions: {}
concurrency:
# Intent: scheduled jobs stomp on each other, but manual runs are mostly independent.
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.triggering_actor }}
cancel-in-progress: true
jobs:
check_versions:
name: Update
runs-on: ubuntu-latest
permissions:
contents: write # we create a branch with updated code, for review
pull-requests: write # we create a PR
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
# Need credentials preserved, to push a branch with changes
persist-credentials: true
- name: Get latest releases
id: get_releases
# We use gh rather than curl, so that our requests can be authenticated and avoid anonymous rate limits
run: |
latest() { gh release --repo "$1" view --json tagName --jq .tagName; }
# Get latest natscli release
RELEASE_NATSCLI="$(latest nats-io/natscli)"
echo >> "$GITHUB_OUTPUT" "release_natscli=$RELEASE_NATSCLI"
# Get latest nsc release
RELEASE_NSC="$(latest nats-io/nsc)"
echo >> "$GITHUB_OUTPUT" "release_nsc=$RELEASE_NSC"
echo "Latest natscli release: $RELEASE_NATSCLI"
echo "Latest nsc release: $RELEASE_NSC"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check current versions
id: check_current
run: |
CURRENT_NATSCLI=$(sed -n 's/^VERSION_stable_nats=//p' < synadia-nats-channels.conf)
CURRENT_NSC=$(sed -n 's/^VERSION_stable_nsc=//p' < synadia-nats-channels.conf)
echo >> "$GITHUB_OUTPUT" "current_natscli=$CURRENT_NATSCLI"
echo >> "$GITHUB_OUTPUT" "current_nsc=$CURRENT_NSC"
echo "Current natscli version: $CURRENT_NATSCLI"
echo "Current nsc version: $CURRENT_NSC"
- name: Update versions if needed
id: update_versions
env:
RELEASE_NATSCLI: ${{ steps.get_releases.outputs.release_natscli }}
RELEASE_NSC: ${{ steps.get_releases.outputs.release_nsc }}
CURRENT_NATSCLI: ${{ steps.check_current.outputs.current_natscli }}
CURRENT_NSC: ${{ steps.check_current.outputs.current_nsc }}
shell: bash
run: |
UPDATED=false
NL=$'\n'
declare -a which_updated=()
commit_message="Update NATS tool versions${NL}${NL}" # paragraph, title vs body
pr_body_table=""
update_one() {
local toolname="$1" config_name="$2" latest="$3" prior="$4"
if [[ "$latest" == "$prior" ]]; then
pr_body_table+="| ${toolname} | \`${prior}\` | (unchanged) |$NL"
return
fi
echo "Updating $toolname from $prior to $latest"
sed -i "s/^VERSION_stable_${config_name}=.*/VERSION_stable_${config_name}=${latest}/" synadia-nats-channels.conf
UPDATED=true
which_updated+=("$toolname")
commit_message+="- ${toolname}: ${prior} → ${latest}$NL"
pr_body_table+="| ${toolname} | \`${prior}\` | \`${latest}\` |$NL"
}
update_one natscli nats "$RELEASE_NATSCLI" "$CURRENT_NATSCLI"
update_one nsc nsc "$RELEASE_NSC" "$CURRENT_NSC"
echo >> "$GITHUB_OUTPUT" "updated=$UPDATED"
echo >> "$GITHUB_OUTPUT" "which_tools=${which_updated[*]}"
echo >> "$GITHUB_OUTPUT" "commit=$(jq -Mcnr --arg cm "$commit_message" --arg table "$pr_body_table" '.message=$cm | .pr_body_table=$table')"
- name: Create Pull Request
if: steps.update_versions.outputs.updated == 'true'
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: |
${{ fromJSON(steps.update_versions.outputs.commit).message }}
title: "Update NATS tool versions: ${{ steps.update_versions.outputs.which_updated }}"
body: |
This PR updates the NATS tool versions in `synadia-nats-channels.conf` to the latest stable releases:
| Tool | Current | New |
|------|---------|-----|
${{ fromJSON(steps.update_versions.outputs.commit).pr_body_table }}
**Release Notes:**
- [natscli releases](https://github.com/nats-io/natscli/releases)
- [nsc releases](https://github.com/nats-io/nsc/releases)
This PR was automatically created by the version update workflow.
branch: auto/update-tool-versions
base: main
delete-branch: true
reviewers: |-2
philpennock
ripienaar
aricart