diff --git a/.github/workflows/semver-checks.yml b/.github/workflows/semver-checks.yml index a089c53..f3a8e0d 100644 --- a/.github/workflows/semver-checks.yml +++ b/.github/workflows/semver-checks.yml @@ -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,32 +63,45 @@ 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]" @@ -92,12 +109,12 @@ jobs: 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,58 @@ jobs: gh pr comment ${{ github.event.number }} --body-file ./report.md exit 1 env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + 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: | + 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 }} \ No newline at end of file diff --git a/README.md b/README.md index 23bef7d..4f34139 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,8 @@ By default, [the kafka consumer is configured](https://github.com/MAIF/yozefu/bl - - Demo of Yozefu. In this demo, the user selects a topic and sees and real time new records published to Kafka. + + Demo of Yozefu. In this demo, the user selects a topic and sees and real time new records published to Kafka.