From b356580fbf05321775df24cf22c2ebad6c717f8e Mon Sep 17 00:00:00 2001 From: CptMoore <39010654+CptMoore@users.noreply.github.com> Date: Wed, 25 Dec 2024 06:34:05 +0100 Subject: [PATCH] Added support for downloading and setting up ModTek within the CI/CD pipeline. --- .github/workflows/ci.yml | 1 + .github/workflows/mod-builder.yml | 72 +++++++++++++++++++++---------- 2 files changed, 51 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1ccb43e8..2b02da15 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,6 +9,7 @@ jobs: uses: ./.github/workflows/mod-builder.yml with: checkout-directory: 'ModTek' + modtek-download-url: '' # don't download ModTek when ModTek is being built! build-script: | build_modtek() { btdir="$1" diff --git a/.github/workflows/mod-builder.yml b/.github/workflows/mod-builder.yml index f24cfc6a..6706f5af 100644 --- a/.github/workflows/mod-builder.yml +++ b/.github/workflows/mod-builder.yml @@ -2,16 +2,29 @@ workflow_call: inputs: checkout-directory: - description: 'The directory the repository will reside in.' + description: 'The directory the repository will reside in. Must not be `.`.' required: true type: string build-script: - description: 'The script that builds the mod, runs within the checkout directory.' + description: 'The script that builds the mod, runs within the checkout-directory.' required: true type: string release-notes: - description: 'The release notes to use for tagged releases.' - default: 'Latest stable version' + description: 'The release notes to use for tagged releases. Default is to only use generated notes.' + required: false + default: '' + type: string + modtek-download-url: + description: 'What ModTek to download and setup. Set to empty to disable.' + required: false + # not to be confused with https://github.com/BattletechModders/ModTek/releases/download/latest/ModTek.zip + # download/latest: latest tag with a release ; latest/download: release labeled latest + default: 'https://github.com/BattletechModders/ModTek/releases/latest/download/ModTek.zip' + type: string + latest-unstable-tag: + description: 'How to name the tag used for released based on the branches master or main. Set to empty to disable.' + required: false + default: 'latest' type: string secrets: MANAGED_ARCHIVE_PW: @@ -26,8 +39,9 @@ jobs: mod-builder: runs-on: ubuntu-latest env: + # dirs BATTLETECH_DIR: ${{ github.workspace }}/BATTLETECH - MODS_DIR: ${{ github.workspace }}/BATTLETECH/Mods + MODS_DIR: ${{ github.workspace }}/BATTLETECH/Mods # only there to make it clear its Mods not mods MANAGED_DIR: ${{ github.workspace }}/BATTLETECH/BattleTech_Data/Managed DIST_DIR: ${{ github.workspace }}/dist steps: @@ -36,12 +50,25 @@ jobs: with: dotnet-version: 9 dotnet-quality: preview - - name: Prepare BATTLETECH + - name: Prepare BATTLETECH/BattleTech_Data/Managed + env: + # TODO migrate these to a org-private git repo or org-private nuget package repo + MANAGED_ARCHIVE_URL: ${{ secrets.MANAGED_ARCHIVE_URL }} + MANAGED_ARCHIVE_PW: ${{ secrets.MANAGED_ARCHIVE_PW }} run: | - curl -L -o Managed.7z ${{ secrets.MANAGED_ARCHIVE_URL }} - mkdir -p "${{ env.MANAGED_DIR }}" - 7z e -p${{ secrets.MANAGED_ARCHIVE_PW }} -o"${{ env.MANAGED_DIR }}" Managed.7z + curl -L -o Managed.7z "$MANAGED_ARCHIVE_URL" + mkdir -p "$MANAGED_DIR" + 7z e -p"$MANAGED_ARCHIVE_PW" -o"$MANAGED_DIR" Managed.7z rm Managed.7z + - name: Prepare BATTLETECH/Mods/ModTek + if: inputs.modtek-download-url != '' + continue-on-error: true # not all mods require ModTek, just more convenient to have it installed by default + env: + MODTEK_DOWNLOAD_URL: ${{ inputs.modtek-download-url }} + run: | + curl -L -o ModTek.zip "$MODTEK_DOWNLOAD_URL" + 7z e -o"$BATTLETECH_DIR" ModTek.zip + rm ModTek.zip - name: Checkout uses: actions/checkout@v4 with: @@ -53,32 +80,33 @@ jobs: run: ${{ inputs.build-script }} - name: Release Latest - if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' + if: inputs.latest-unstable-tag != '' && ( github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' ) working-directory: ${{ inputs.checkout-directory }} + env: + LATEST_UNSTABLE_TAG: ${{ inputs.latest-unstable-tag }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - gh release delete latest --cleanup-tag || true - git tag -d latest || true - git push --delete origin refs/tags/latest || true - git tag latest - git push --force origin refs/tags/latest - gh release create latest "$DIST_DIR"/* \ + gh release delete "$LATEST_UNSTABLE_TAG" --cleanup-tag || true + git tag -d "$LATEST_UNSTABLE_TAG" || true + git push --delete origin refs/tags/"$LATEST_UNSTABLE_TAG" || true + git tag "$LATEST_UNSTABLE_TAG" + git push --force origin refs/tags/"$LATEST_UNSTABLE_TAG" + gh release create "$LATEST_UNSTABLE_TAG" "$DIST_DIR"/* \ --generate-notes \ --title "Latest (unstable)" \ --verify-tag \ --prerelease - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Release Tag if: startsWith(github.ref, 'refs/tags/v') working-directory: ${{ inputs.checkout-directory }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RELEASE_NOTES: ${{ inputs.release-notes }} run: | gh release delete "$GITHUB_REF_NAME" || true gh release create "$GITHUB_REF_NAME" "$DIST_DIR"/* \ --generate-notes \ - --notes "$RELEASE_NOTES" \ + ${RELEASE_NOTES:+ --notes "$RELEASE_NOTES"} \ --verify-tag \ --latest - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - RELEASE_NOTES: ${{ inputs.release-notes }}