Skip to content

Commit

Permalink
ci: compute the next version instead of failing the github action
Browse files Browse the repository at this point in the history
  • Loading branch information
Mcdostone committed Feb 13, 2025
1 parent 4a487d9 commit dd238f9
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 20 deletions.
107 changes: 89 additions & 18 deletions .github/workflows/semver-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ jobs:
if [[ "${{ github.ref_name }}" = "main" ]]; then
exit 1
fi
cargo-semver-checks:
setup:
needs: check-branches
outputs:
currentVersion: ${{ steps.current.outputs.version }}
nextVersion: ${{ steps.next.outputs.version }}
nextStep: ${{ steps.nextStep.outputs.nextStep }}
permissions:
pull-requests: write
contents: write
Expand All @@ -59,45 +63,58 @@ jobs:
with:
toolchain: stable
- uses: Swatinem/rust-cache@v2
- name: Install cargo-semver-checks
run: cargo install cargo-semver-checks
- name: List the releases on GitHub
id: current
run: echo "version=$(git tag --sort=-creatordate | head -n 1)" >> "$GITHUB_OUTPUT"
- name: Get next version
id: next
run: echo "version=v$(cargo pkgid --manifest-path crates/bin/Cargo.toml | cut -d '@' -f2)" >> "$GITHUB_OUTPUT"
- name: Make sure version is updated
- name: Compute next step
id: nextStep
if: ${{ steps.current.outputs.version == steps.next.outputs.version }}
run: |
echo "::warning title=Next version:: Last public version is '${{ steps.current.outputs.version }}' but version of this branch is '${{ steps.next.outputs.version }}'. Did you forget to update the version? More details at https://github.com/MAIF/yozefu/blob/main/docs/release/README.md"
printf 'This pull request is not ready because the crate version is equals to the latest git tag version `' > report.md
printf "${{ steps.next.outputs.version }}" >> report.md
printf '`. I think you forgot to bump the version. More details at https://github.com/MAIF/yozefu/blob/main/docs/release/README.md' >> report.md
gh pr comment ${{ github.event.number }} --body-file ./report.md
exit 1
env:
GH_TOKEN: ${{ github.token }}
if [[ "${{ steps.current.outputs.version }}" == "${{ steps.next.outputs.version }}" ]]; then
echo "nextStep=compute" >> "$GITHUB_OUTPUT"
else
echo "nextStep=nope" >> "$GITHUB_OUTPUT"
fi
cargo-semver-checks:
needs: setup
permissions:
pull-requests: write
contents: write
runs-on: ubuntu-latest
if: ${{ needs.setup.outputs.nextStep != 'compute' }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- uses: Swatinem/rust-cache@v2
- name: Install cargo-semver-checks
run: cargo install cargo-semver-checks
- name: Show release type
id: semver
run: |
chmod u+x ./.github/workflows/semver.sh
echo "release=$(./.github/workflows/semver.sh diff ${{ steps.current.outputs.version }} ${{ steps.next.outputs.version }})" >> "$GITHUB_OUTPUT"
echo "release=$(bash ./.github/workflows/semver.sh diff ${{ needs.setup.outputs.currentVersion }} ${{ needs.setup.outputs.nextVersion }})" >> "$GITHUB_OUTPUT"
- name: Prepare report.md
if: ${{ steps.next.outputs.version == '' }}
if: ${{ needs.setup.outputs.nextVersion == '' }}
run: |
{
printf "> [!WARNING]"
printf "> According to \`cargo-semver-checks\`, the next release version doesn\'t respect semantic versioning."
printf '```bash'
} > ./report.md
- name: Run cargo semver-checks
if: ${{ steps.next.outputs.version != '' && steps.semver.outputs.release != '' }}
if: ${{ needs.setup.outputs.nextVersion != '' && steps.semver.outputs.release != '' }}
id: check
run: |
printf "\`cargo-semver-checks\` has detected some issues: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\n" > report.md
printf '```bash' >> report.md
cargo semver-checks --color never --package yozefu-lib --package yozefu-app --package yozefu-wasm-types --package yozefu-command --baseline-rev "${{ steps.current.outputs.version }}" --release-type "${{ steps.semver.outputs.release }}" 2>&1 | tee -a report.md
cargo semver-checks --color never --package yozefu-lib --package yozefu-app --package yozefu-wasm-types --package yozefu-command --baseline-rev "${{ needs.setup.outputs.currentVersion }}" --release-type "${{ steps.semver.outputs.release }}" 2>&1 | tee -a report.md
if [[ "${PIPESTATUS[0]}" != "0" ]]; then
printf '```' >> report.md
exit 1
Expand All @@ -109,4 +126,58 @@ jobs:
gh pr comment ${{ github.event.number }} --body-file ./report.md
exit 1
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish semver-checks report
if: ${{ steps.check.outcome != 'success' }}
run: |
gh pr comment ${{ github.event.number }} --body-file ./report.md
exit 1
compute-next-version:
needs: setup
permissions:
pull-requests: write
contents: write
if: ${{ needs.setup.outputs.nextStep == 'compute' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- uses: Swatinem/rust-cache@v2
- name: Install cargo-semver-checks
run: cargo install cargo-semver-checks
- name: Determine the next version
id: bump
continue-on-error: true
run: |
b="major"
for t in patch minor; do
if cargo semver-checks --color never --package yozefu-lib --package yozefu-app --package yozefu-wasm-types --package yozefu-command --baseline-rev "${{ needs.setup.outputs.currentVersion }}" --release-type "$t"; then
b="$t"
break
fi
done
echo $b
echo "bump=$b" >> "$GITHUB_OUTPUT"
- name: Comment the pull request
run: |

Check failure on line 168 in .github/workflows/semver-checks.yml

View workflow job for this annotation

GitHub Actions / actionlint

shellcheck reported issue in this script: SC2028:info:7:8: echo may not expand escape sequences. Use printf

Check failure on line 168 in .github/workflows/semver-checks.yml

View workflow job for this annotation

GitHub Actions / actionlint

"github.head_ref" is potentially untrusted. avoid using it directly in inline scripts. instead, pass it through an environment variable. see https://docs.github.com/en/actions/security-for-github-actions/security-guides/security-hardening-for-github-actions for more details
echo "::info title=Next version:: Last public version is '${{ needs.setup.outputs.currentVersion }}' but version of this branch is '${{ needs.setup.outputs.nextVersion }}'."
{
printf "This pull request is not ready because version \`%s\` is already published." "${{ needs.setup.outputs.currentVersion }}"
printf "\nAccording to \`cargo-semver-checks\`, the next version should be \`v%s\`:" "$(bash .github/workflows/semver.sh bump ${{ steps.bump.outputs.bump }} ${{ needs.setup.outputs.currentVersion }} | tr -d "\n")"
printf "\n"
echo '```shell'
echo "git checkout \'${{ toJSON(github.head_ref) }}'"
echo "cargo release ${{ steps.bump.outputs.bump }} --no-push --no-publish --no-confirm --execute"
echo "git push"
echo '```'
echo "More details at https://github.com/MAIF/yozefu/blob/main/docs/release/README.md"
} >> report.md
gh pr comment ${{ github.event.number }} --body-file ./report.md
env:
GH_TOKEN: ${{ github.token }}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ By default, [the kafka consumer is configured](https://github.com/MAIF/yozefu/bl

<a href="https://mcdostone.github.io/yozefu.mp4" target="_blank">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/MAIF/yozefu/raw/HEAD/docs/screenshots/light.png">
<img alt="Demo of Yozefu. In this demo, the user selects a topic and sees and real time new records published to Kafka." src="./docs/screenshots/light.png">
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/MAIF/yozefu/raw/HEAD/docs/screenshots/dark.png">
<img alt="Demo of Yozefu. In this demo, the user selects a topic and sees and real time new records published to Kafka." src="https://github.com/MAIF/yozefu/raw/HEAD/docs/screenshots/light.png">
</picture>
</a>

Expand Down

0 comments on commit dd238f9

Please sign in to comment.