Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions .github/workflows/up-spec-badge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Update up-spec compatibility badge

on:
push:
branches: [ main ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that the whole mechanism will (currently) only work when we make changes to the main branch. However, IMHO we will need to be able to do this on (version specific) branches as well. For example once we have released stable versions 1.0.0 and 2.0.0 which implement different versions of the spec, we will need to be able to apply this mechanism on version specific bug-fix branches. AFAICT this mechanism should generally also work in such a scenario, but will need to consider the branch that we are pushing to in several places, or am I mistaken?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that the whole mechanism will (currently) only work when we make changes to the main branch. However, IMHO we will need to be able to do this on (version specific) branches as well. For example once we have released stable versions 1.0.0 and 2.0.0 which implement different versions of the spec, we will need to be able to apply this mechanism on version specific bug-fix branches. AFAICT this mechanism should generally also work in such a scenario, but will need to consider the branch that we are pushing to in several places, or am I mistaken?

workflow_dispatch:

permissions:
contents: write

jobs:
badge:
if: github.event.head_commit.author.name != 'github-actions[bot]'
runs-on: ubuntu-latest
steps:
- name: Checkout (with submodules)
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- name: Fetch tags for up-spec submodule
run: |
git -C up-spec fetch --tags || true

- name: Determine current up-spec tag
id: current
run: |
if CUR=$(git -C up-spec describe --tags --exact-match 2>/dev/null); then
echo "current_tag=$CUR" >> $GITHUB_OUTPUT
else
CUR=$(git -C up-spec describe --tags --abbrev=0 2>/dev/null || echo "unknown")
echo "current_tag=$CUR" >> $GITHUB_OUTPUT
fi

- name: Get latest up-spec tag (including pre-releases)
id: latest
run: |
TAGS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/eclipse-uprotocol/up-spec/tags | jq -r '.[].name')
if [ -z "$TAGS" ]; then
echo "Failed to retrieve tags"
exit 1
fi
# Sort semver with pre-release awareness (simple approach).
LATEST=$(printf "%s\n" $TAGS | sort -V | tail -n1)
echo "latest_tag=$LATEST" >> $GITHUB_OUTPUT

- name: Decide badge color
id: color
run: |
if [ "${{ steps.current.outputs.current_tag }}" = "${{ steps.latest.outputs.latest_tag }}" ]; then
echo "color=green" >> $GITHUB_OUTPUT
else
echo "color=red" >> $GITHUB_OUTPUT
fi

- name: Build badge line
id: badge
run: |
CUR=${{ steps.current.outputs.current_tag }}
COLOR=${{ steps.color.outputs.color }}
BADGE_URL="https://img.shields.io/badge/up--spec-${CUR//-/%2D}-${COLOR}"
LINK_URL="https://github.com/eclipse-uprotocol/up-spec/tree/${CUR}"
echo "badge_line=[![up-spec](${BADGE_URL})](${LINK_URL})" >> $GITHUB_OUTPUT

- name: Update README
run: |
README="README.md"
START="<!-- up-spec-badge-start -->"
END="<!-- up-spec-badge-end -->"
NEW="${{ steps.badge.outputs.badge_line }}"
if grep -q "$START" "$README"; then
EXISTING=$(awk "/$START/{getline; print}" "$README")
if [ "$EXISTING" = "$NEW" ]; then
echo "No change needed."
exit 0
fi
awk -v s="$START" -v e="$END" -v n="$NEW" '
$0==s { print; getline; print n; while (getline && $0!=e); print e; next }
{ print }
' "$README" > README.tmp && mv README.tmp "$README"
else
printf "%s\n%s\n%s\n\n" "$START" "$NEW" "$END" | cat - "$README" > README.tmp && mv README.tmp "$README"
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add README.md
git commit -m "chore: update up-spec compatibility badge" || echo "Nothing to commit"
git push || echo "Push skipped (likely not on main)."

- name: Summary
run: |
echo "Current: ${{ steps.current.outputs.current_tag }}" >> $GITHUB_STEP_SUMMARY
echo "Latest: ${{ steps.latest.outputs.latest_tag }}" >> $GITHUB_STEP_SUMMARY
echo "Color: ${{ steps.color.outputs.color }}" >> $GITHUB_STEP_SUMMARY
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Eclipse uProtocol Rust library

<!-- up-spec-badge-start -->
[![up-spec](https://img.shields.io/badge/up--spec-v1.6.0--alpha.7-green)](https://github.com/eclipse-uprotocol/up-spec/tree/v1.6.0-alpha.7)
<!-- up-spec-badge-end -->


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if we could also update the link in the subsequent line(s) dynamically, based on the current tag ...

This is the [uProtocol v1.6.0-alpha.7 Language Library](https://github.com/eclipse-uprotocol/uprotocol-spec/blob/v1.6.0-alpha.7/languages.adoc) for the Rust programming language.

The crate can be used to
Expand Down