-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: compute the next version instead of failing the github action
- Loading branch information
Showing
2 changed files
with
92 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -109,4 +126,59 @@ 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
|
||
echo "::info title=Next version:: Last public version is '${{ needs.setup.outputs.currentVersion }}' but version of this branch is '${{ needs.setup.outputs.nextVersion }}'." | ||
{ | ||
echo "This pull request is not ready because the crate version is equals to the latest git tag version \`" | ||
echo "${{ needs.setup.outputs.currentVersion }}" | ||
echo "\`. I think you forgot to bump the version. More details at https://github.com/MAIF/yozefu/blob/main/docs/release/README.md" | ||
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' | ||
git checkout ${{ github.head_ref }} | ||
echo "cargo release ${{ steps.bump.outputs.bump }} --no-push --no-publish --no-confirm --execute" | ||
echo "git push" | ||
echo '```' | ||
} >> report.md | ||
gh pr comment ${{ github.event.number }} --body-file ./report.md | ||
env: | ||
GH_TOKEN: ${{ github.token }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters