Skip to content

[Version request]

[Version request] #53

name: Build version on issue request
on:
issues:
types: [opened, reopened]
jobs:
check_if_build_needed:
runs-on: ubuntu-latest
outputs:
is_valid_request: ${{ steps.check.outputs.is_valid_request }}
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: echo "version="$(echo "$BODY" | tail -n1) >> $GITHUB_OUTPUT
- id: exist
name: Check if version already exists in release
if: ${{ steps.check.outputs.is_valid_request == 'true' }}
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
env:
GH_TOKEN: ${{ github.token }}
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.value == 0 }}
secrets: inherit
strategy:
fail-fast: false
matrix:
config:
- {
name: Windows,
os: windows-latest
}
- {
name: Linux,
os: ubuntu-latest
}
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 }}
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.value == 0 }}
steps:
- name: Notify issue
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."
env:
GH_TOKEN: ${{ github.token }}
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.value != 0 }}
steps:
- name: Notify issue
run: |
echo "Binaries for ${{ needs.check_if_build_needed.outputs.version }} are already available in the [latest release](https://github.com/${{ github.repository }}/releases/tag/latest)." > body.txt
echo -en '\n' >> body.txt
echo You can close this issue. If you need an updated build for the same Minecraft version in the future, you can reopen this issue to trigger a new build instead of creating a new one. >> body.txt
gh issue comment ${{ github.event.issue.html_url }} --repo ${{ github.repository }} --body-file body.txt
env:
GH_TOKEN: ${{ github.token }}
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@v4
with:
name: botcraft-Linux
path: linux
- name: Download Windows artifact
uses: actions/download-artifact@v4
with:
name: botcraft-Windows
path: windows
- name: Download doc artifact
uses: actions/download-artifact@v4
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
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 }}
env:
GH_TOKEN: ${{ github.token }}
- name: Comment on associated issue
run: |
echo "New binaries available in the [latest release](https://github.com/${{ github.repository }}/releases/tag/latest) for version ${{ needs.check_if_build_needed.outputs.version }}" > body.txt
echo -en '\n' >> body.txt
echo You can now close this issue. If you need an updated build for the same Minecraft version in the future, you can reopen this issue to trigger a new build instead of creating a new issue. >> body.txt
gh issue comment ${{ github.event.issue.html_url }} --repo ${{ github.repository }} --body-file body.txt
env:
GH_TOKEN: ${{ github.token }}