Skip to content

Commit

Permalink
Added support for downloading and setting up ModTek within the CI/CD …
Browse files Browse the repository at this point in the history
…pipeline.
  • Loading branch information
CptMoore committed Dec 25, 2024
1 parent 97e2950 commit b356580
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
72 changes: 50 additions & 22 deletions .github/workflows/mod-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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 }}

0 comments on commit b356580

Please sign in to comment.