[Version request] #250
This file contains hidden or 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
| name: Build version on issue request | |
| on: | |
| issues: | |
| types: [opened, reopened] | |
| # Only allow one running build at the same time | |
| concurrency: | |
| group: ${{ github.workflow }} | |
| permissions: | |
| contents: write | |
| issues: write | |
| jobs: | |
| check_if_build_needed: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| is_valid_request: ${{ steps.check.outputs.is_valid_request }} | |
| is_valid_version: ${{ steps.retrieve.outputs.is_valid_version }} | |
| version: ${{ steps.retrieve.outputs.version }} | |
| value: ${{ steps.exist.outputs.value }} | |
| steps: | |
| - id: check | |
| name: Check if issue is a request | |
| run: echo "is_valid_request=${{ startsWith(github.event.issue.title, '[Version request]') }}" >> $GITHUB_OUTPUT | |
| - id: retrieve | |
| name: Retrieve the version from body | |
| if: ${{ steps.check.outputs.is_valid_request == 'true' }} | |
| env: | |
| BODY: ${{ github.event.issue.body }} | |
| run: | | |
| VERSION="$(echo "$BODY" | tail -n1 | tr -d '\r')" | |
| if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "is_valid_version=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "is_valid_version=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| - id: exist | |
| name: Check if version already exists in release | |
| if: ${{ steps.check.outputs.is_valid_request == 'true' && steps.retrieve.outputs.is_valid_version == 'true' }} | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: echo "value="$(gh release view latest --repo ${{ github.repository }} --json assets -q "[.assets.[].name | select(endswith(\"${{ steps.retrieve.outputs.version }}.zip\"))] | length") >> $GITHUB_OUTPUT | |
| os_matrix: | |
| needs: check_if_build_needed | |
| name: ${{ matrix.config.name }} | |
| if: ${{ needs.check_if_build_needed.outputs.is_valid_request == 'true' && needs.check_if_build_needed.outputs.is_valid_version == 'true' && needs.check_if_build_needed.outputs.value == 0 }} | |
| secrets: inherit | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| config: | |
| - { | |
| name: Windows, | |
| os: windows-latest, | |
| run_physics_tests: false | |
| } | |
| - { | |
| name: Linux, | |
| os: ubuntu-latest, | |
| run_physics_tests: true | |
| } | |
| uses: ./.github/workflows/botcraft_build.yml | |
| with: | |
| os: ${{ matrix.config.os }} | |
| version: ${{ needs.check_if_build_needed.outputs.version }} | |
| issue: ${{ github.event.issue.html_url }} | |
| run_physics_tests: ${{ matrix.config.run_physics_tests }} | |
| notify_build_started: | |
| runs-on: ubuntu-latest | |
| needs: check_if_build_needed | |
| if: ${{ needs.check_if_build_needed.outputs.is_valid_request == 'true' && needs.check_if_build_needed.outputs.is_valid_version == 'true' && needs.check_if_build_needed.outputs.value == 0 }} | |
| steps: | |
| - name: Notify issue | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: gh issue comment ${{ github.event.issue.html_url }} --repo ${{ github.repository }} -b "Build process started. You can follow the build progress [here](https://github.com/${{ github.repository }}/actions) or subscribe to this issue to be notified when binaries are ready." | |
| notify_already_exists: | |
| runs-on: ubuntu-latest | |
| needs: check_if_build_needed | |
| if: ${{ needs.check_if_build_needed.outputs.is_valid_request == 'true' && needs.check_if_build_needed.outputs.is_valid_version == 'true' && needs.check_if_build_needed.outputs.value != 0 }} | |
| steps: | |
| - name: Notify and close issue | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: gh issue close ${{ github.event.issue.html_url }} --repo ${{ github.repository }} -c "Binaries for ${{ needs.check_if_build_needed.outputs.version }} are already available in the [latest release](https://github.com/${{ github.repository }}/releases/tag/latest)." -r "duplicate" | |
| notify_invalid_version: | |
| runs-on: ubuntu-latest | |
| needs: check_if_build_needed | |
| if: ${{ needs.check_if_build_needed.outputs.is_valid_request == 'true' && needs.check_if_build_needed.outputs.is_valid_version == 'false' }} | |
| steps: | |
| - name: Notify invalid version | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: gh issue close ${{ github.event.issue.html_url }} --repo ${{ github.repository }} -c "The version in this request doesn't match the expected format (e.g. \`1.21.11\`). Please use the version request template to create your issue." -r "not planned" | |
| update_release: | |
| runs-on: ubuntu-latest | |
| needs: | |
| - os_matrix | |
| - notify_build_started | |
| - check_if_build_needed | |
| steps: | |
| - name: Download Linux artifact | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: botcraft-Linux | |
| path: linux | |
| - name: Download Windows artifact | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: botcraft-Windows | |
| path: windows | |
| - name: Download doc artifact | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: botcraft-doc | |
| path: doc | |
| - name: Rename artifacts | |
| run: | | |
| mv linux/botcraft.zip botcraft-linux-${{ needs.check_if_build_needed.outputs.version }}.zip | |
| mv windows/botcraft.zip botcraft-windows-${{ needs.check_if_build_needed.outputs.version }}.zip | |
| mv doc/doc.zip botcraft-doc-${{ needs.check_if_build_needed.outputs.version }}.zip | |
| - name: Upload files to release | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: > | |
| gh release upload latest | |
| botcraft-linux-${{ needs.check_if_build_needed.outputs.version }}.zip | |
| botcraft-windows-${{ needs.check_if_build_needed.outputs.version }}.zip | |
| botcraft-doc-${{ needs.check_if_build_needed.outputs.version }}.zip | |
| --repo ${{ github.repository }} | |
| - name: Close associated issue | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: gh issue close ${{ github.event.issue.html_url }} --repo ${{ github.repository }} -c "New binaries available in the [latest release](https://github.com/${{ github.repository }}/releases/tag/latest) for version ${{ needs.check_if_build_needed.outputs.version }}" -r "completed" |