-
Notifications
You must be signed in to change notification settings - Fork 16
Feat/up spec badge #294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Feat/up spec badge #294
Changes from all commits
831fa64
dd3987a
7a1d246
dd5cf46
4a1f3a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| name: Update up-spec compatibility badge | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ main ] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
senseix21 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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) | ||
senseix21 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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}" | ||
senseix21 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| echo "badge_line=[](${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)." | ||
senseix21 marked this conversation as resolved.
Show resolved
Hide resolved
senseix21 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,10 @@ | ||
| # Eclipse uProtocol Rust library | ||
|
|
||
| <!-- up-spec-badge-start --> | ||
| [](https://github.com/eclipse-uprotocol/up-spec/tree/v1.6.0-alpha.7) | ||
| <!-- up-spec-badge-end --> | ||
|
|
||
|
|
||
senseix21 marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
There was a problem hiding this comment.
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?