-
Notifications
You must be signed in to change notification settings - Fork 66
feat: add latest-snapshot as a badge in README.md #2247
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?
Changes from 2 commits
fc3e41f
f497b77
9bd5f39
d14fd9a
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,50 @@ | ||
name: trigger-update-badge.yml | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
required: true | ||
description: 'a semver string denoting the version' | ||
update-badge: | ||
type: string | ||
required: false | ||
description: 'notEmpty if is a versioned snapshot' | ||
workflow_call: | ||
inputs: | ||
version: | ||
type: string | ||
required: true | ||
description: 'a semver string denoting the version' | ||
update-badge: | ||
type: string | ||
required: false | ||
description: 'notEmpty if is a versioned snapshot' | ||
jobs: | ||
update-snapshot-badge: | ||
name: 'Update Snapshot badge in README.md' | ||
permissions: | ||
contents: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v5 | ||
- name: Update README badge | ||
run: | | ||
VERSION="${{ inputs.version }}" | ||
ESCAPED_VERSION="${VERSION//-/--}" | ||
UPDATE_BADGE="${{ inputs.update-badge }}" | ||
if [ -n "$UPDATE_BADGE" ]; then | ||
sed -i "s|^\[snapshot-shield\]:.*|[snapshot-shield]:https://img.shields.io/badge/latest--snapshot-$ESCAPED_VERSION-blue?style=for-the-badge|" 'README.md' | ||
fi | ||
- name: Commit changes | ||
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. That is not the best practice, as badge changes should not create a trace in the repositories history. I found several solutions for such badges which provide the data using an api that stores the intermediate value. I think I remember, that it is possible to use an workflow artifact that is used as data, or something like that. And please take care, that the file end with a newline, thanks! 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. I’ve looked into it and haven’t found a way to do this without a commit or new dependencies. From what I understand, Action outputs and artifacts cannot be accessed publicly, so the version must be persisted somewhere accessible to use it for a dynamic badge. If you have any other possibility that you would like me to try and explore let me know. |
||
id: commit-update-snapshot-badge | ||
shell: bash | ||
run: | | ||
git add . | ||
if git diff --cached --quiet; then | ||
echo "Not a versioned Snapshot" | ||
else | ||
git config user.name "eclipse-tractusx-bot" | ||
git config user.email "tractusx-bot@eclipse.org" | ||
git commit --message "Update snapshot badge" | ||
git push origin HEAD | ||
fi |
Uh oh!
There was an error while loading. Please reload this page.