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
13 changes: 13 additions & 0 deletions .github/workflows/publish-new-snapshot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
VERSION: ${{ steps.get-version.outputs.VERSION }}
UPDATE-BADGE: ${{ steps.get-version.outputs.UPDATE-BADGE }}
steps:
- uses: actions/checkout@v5
- name: "Get version"
Expand All @@ -83,6 +84,7 @@ jobs:

if [[ "${{ github.event.workflow_run.event }}" == "schedule" || "${{ inputs.dated_snapshot }}" == "true" ]]; then
echo "VERSION=$RELEASE_VERSION_MAJOR.$RELEASE_VERSION_MINOR.$RELEASE_VERSION_PATCH-$(date +"%Y%m%d")-SNAPSHOT" >> "$GITHUB_OUTPUT"
echo "UPDATE-BADGE=true" >> "$GITHUB_OUTPUT"
else
echo "VERSION=$RELEASE_VERSION_MAJOR.$RELEASE_VERSION_MINOR.$RELEASE_VERSION_PATCH-SNAPSHOT" >> "$GITHUB_OUTPUT"
fi
Expand Down Expand Up @@ -121,3 +123,14 @@ jobs:
secrets: inherit
with:
version: ${{ needs.determine-version.outputs.VERSION }}

update-snapshot-badge:
name: 'Update Snapshot badge in README.md'
permissions:
contents: write
needs: [determine-version]
uses: ./.github/workflows/trigger-update-badge.yml
secrets: inherit
with:
version: ${{ needs.determine-version.outputs.VERSION }}
update-badge: ${{ needs.determine-version.outputs.UPDATE-BADGE }}
71 changes: 71 additions & 0 deletions .github/workflows/trigger-update-badge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#################################################################################
# Copyright (c) 2025 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License, Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# SPDX-License-Identifier: Apache-2.0
#################################################################################


---
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
Copy link
Contributor

Choose a reason for hiding this comment

The 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!

Choose a reason for hiding this comment

The 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.
Since the version is only defined within the Action:
• Static badge: We would need to commit the updated version each time (current approach).
• Dynamic badge: We would need a publicly accessible data source fed from the Action.

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.
That leads us back to the commits, and the only way this wouldn't leave a trace in tractus would be by using an external storage, which would add a dependency.

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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
[![Contributors][contributors-shield]][contributors-url]
[![Stargazers][stars-shield]][stars-url]
[![Apache 2.0 License][license-shield]][license-url]

[![Latest Release][release-shield]][release-url]
[![Latest Snapshot][snapshot-shield]]()

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=eclipse-tractusx_tractusx-edc&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=eclipse-tractusx_tractusx-edc)

Expand Down Expand Up @@ -83,3 +85,5 @@ See [LICENSE](https://github.com/eclipse-tractusx/tractusx-edc/blob/main/LICENSE
[release-shield]: https://img.shields.io/github/v/release/eclipse-tractusx/tractusx-edc.svg?style=for-the-badge

[release-url]: https://github.com/eclipse-tractusx/tractusx-edc/releases

[snapshot-shield]:https://img.shields.io/badge/latest--snapshot-Error-red?style=for-the-badge
Loading