CI/CD Switch to Env Context for Branch ID in AdminMod Checks #327
This file contains 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
# This workflow will build a .NET project | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net | |
name: CI-CD-Pipeline | |
on: | |
push: | |
branches: | |
- main | |
- beta | |
paths: | |
- '**/Si_*/**' | |
- '!*.md' | |
- '!*.json' | |
env: | |
BUILD_TYPE: Release | |
jobs: | |
beta-check: | |
runs-on: ubuntu-latest | |
steps: | |
- name: generate new branch variable for checkout@v4 | |
id: branch-ident | |
run: echo "branch_identifier=$(echo ${GITHUB_REF#refs/heads/})" >> "$GITHUB_OUTPUT" | |
- name: beta branch detected | |
if: ${{ github.ref == 'refs/heads/beta' }} | |
run: echo "Using non-standard reference package for branch ${{ steps.branch-ident.outputs.branch_identifier }}" | |
- name: non-beta branch detected | |
if: ${{ github.ref != 'refs/heads/beta' }} | |
run: echo "Using standard reference package for branch ${{ steps.branch-ident.outputs.branch_identifier }}" | |
outputs: | |
branch_identifier: ${{ steps.branch-ident.outputs.branch_identifier }} | |
get-commit-number: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Generate the commit number | |
id: commit-number | |
run: | | |
echo "comnum=$(git log --oneline | wc -l)" >> "$GITHUB_OUTPUT" | |
outputs: | |
comnum: ${{ steps.commit-number.outputs.comnum }} | |
find-if-nuget-update-is-needed: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Save branch name | |
shell: bash | |
run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ env.BRANCH_NAME }} | |
- uses: dorny/paths-filter@v3 | |
id: checkAdminMod | |
with: | |
base: ${{ env.BRANCH_NAME }} | |
ref: ${{ env.BRANCH_NAME }} | |
filters: | | |
admin-updated: | |
- 'Si_AdminModdd/**' | |
# run only if 'workflows' files were changed | |
- name: adminmod updated | |
if: steps.checkAdminMod.outputs.admin-updated == 'true' | |
run: echo "AdminMod Update Found." | |
# run only if not 'workflows' files were changed | |
- name: no adminmod updates | |
if: steps.checkAdminMod.outputs.admin-updated != 'true' | |
run: echo "No AdminMod Update Found. Skipping nuget packages..." | |
outputs: | |
admin-updated: ${{ steps.checkAdminMod.outputs.admin-updated }} | |
create-package: | |
needs: [ find-if-nuget-update-is-needed, get-commit-number, beta-check ] | |
if: needs.find-if-nuget-update-is-needed.outputs.admin-updated == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ needs.beta-check.outputs.branch_identifier }} | |
- name: Game References | |
uses: actions/checkout@v4 | |
with: | |
repository: ${{ secrets.PRIV_R }} | |
token: ${{ secrets.FGAT_PRIV_R }} | |
ref: ${{ needs.beta-check.outputs.branch_identifier }} | |
path: references | |
- name: Copy References | |
run: | | |
cp -r references/. include | |
- name: Download FixNullableAttribute | |
uses: robinraju/[email protected] | |
with: | |
repository: "data-bomb/FixNullableAttribute" | |
latest: true | |
fileName: "FixNullableAttribute.dll" | |
tarBall: false | |
zipBall: false | |
- name: Move FixNullableAttribute | |
run: | | |
mv FixNullableAttribute.dll include/net6.0/ | |
- name: Setup .NET SDK | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: 6.0.x | |
- name: Restore | |
run: | | |
cd Si_AdminMod | |
dotnet restore | |
- name: Build | |
run: | | |
cd Si_AdminMod | |
dotnet build --no-restore -c ${{env.BUILD_TYPE}} | |
- name: Test | |
run: | | |
cd Si_AdminMod | |
dotnet test -c ${{env.BUILD_TYPE}} --no-build | |
- name: Pack NuGet | |
run: | | |
cd Si_AdminMod | |
dotnet pack -c ${{env.BUILD_TYPE}} --no-build --output . /p:Version=2.0.${{ needs.get-commit-number.outputs.comnum }} | |
- name: Push to NuGet | |
run: | | |
cd Si_AdminMod | |
dotnet nuget push "*.nupkg" --api-key ${{secrets.NUGET_ADMINMOD_API_KEY}} --source https://api.nuget.org/v3/index.json | |
- name: Wait for publishing | |
uses: juliangruber/[email protected] | |
with: | |
time: 10m | |
fanout: | |
if: ${{ !failure() && !cancelled() }} | |
needs: [ find-if-nuget-update-is-needed, create-package, beta-check ] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ needs.beta-check.outputs.branch_identifier }} | |
- name: Generate matrix with all modules of the repo | |
id: set-matrix | |
run: | | |
echo "matrix=$(ls -l | grep '^d' | awk -F ' ' '{print $9}' | grep -Po 'Si.*' | jq -R -s -c 'split("\n") | map(select(length > 0))')" >> "$GITHUB_OUTPUT" | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
build: | |
if: ${{ !failure() && !cancelled() }} | |
needs: fanout | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
path: ${{ fromJson(needs.fanout.outputs.matrix) }} | |
steps: | |
- name: Prepare environment sha | |
shell: bash | |
run: echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV | |
- name: Prepare environment pwd | |
shell: bash | |
run: echo "START_DIR=`pwd`" >> $GITHUB_ENV | |
- name: Save branch name | |
shell: bash | |
run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV | |
- name: beta branch detected | |
if: ${{ github.ref == 'refs/heads/beta' }} | |
run: echo "Using beta branch" | |
- name: main branch detected | |
if: ${{ github.ref == 'refs/heads/main' }} | |
run: echo "Using main branch" | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ env.BRANCH_NAME }} | |
- name: Game References | |
uses: actions/checkout@v4 | |
with: | |
repository: ${{ secrets.PRIV_R }} | |
token: ${{ secrets.FGAT_PRIV_R }} | |
ref: ${{ env.BRANCH_NAME }} | |
path: references | |
- name: Copy References | |
run: | | |
cp -r references/. include | |
- name: Download FixNullableAttribute | |
uses: robinraju/[email protected] | |
with: | |
repository: "data-bomb/FixNullableAttribute" | |
latest: true | |
fileName: "FixNullableAttribute.dll" | |
tarBall: false | |
zipBall: false | |
- name: Move FixNullableAttribute | |
run: | | |
mv FixNullableAttribute.dll include/net6.0/ | |
- name: Download QList | |
uses: robinraju/[email protected] | |
with: | |
repository: "dodad-2/QList" | |
latest: true | |
fileName: "QList.dll" | |
tarBall: false | |
zipBall: false | |
- name: Move QList | |
run: | | |
mv QList.dll include/ | |
- name: Setup .NET 6 | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: 6.0.x | |
- name: Restore dependencies | |
run: | | |
cd ${{ matrix.path }} | |
dotnet restore | |
- name: Build | |
run: | | |
cd ${{ matrix.path }} | |
dotnet build --no-restore -c ${{env.BUILD_TYPE}} | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.path }}-build-${{ env.GITHUB_SHA_SHORT }} | |
path: ${{ matrix.path }}/bin/${{env.BUILD_TYPE}}/**/${{ matrix.path }}.dll | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: dedicated-server-${{ matrix.path }}-build-${{ env.GITHUB_SHA_SHORT }} | |
path: ${{ matrix.path }}/bin/${{env.BUILD_TYPE}}/netstandard2.1/${{ matrix.path }}.dll | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: listen-server-${{ matrix.path }}-build-${{ env.GITHUB_SHA_SHORT }} | |
path: ${{ matrix.path }}/bin/${{env.BUILD_TYPE}}/net6.0/${{ matrix.path }}.dll | |
publish: | |
if: github.event_name == 'push' && ${{ !failure() && !cancelled() }} | |
permissions: | |
contents: write | |
needs: [ get-commit-number, build, fanout, beta-check ] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Prepare env | |
shell: bash | |
run: echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV | |
- uses: actions/checkout@v4 | |
with: | |
sparse-checkout: . | |
ref: ${{ needs.beta-check.outputs.branch_identifier }} | |
- name: Make output paths | |
run: | | |
mkdir -p release/dedi/Plugins | |
mkdir -p release/dedi/Mods/disabled | |
mkdir -p release/dedi/UserData | |
mkdir -p release/listen/Plugins | |
mkdir -p release/listen/Mods/disabled | |
mkdir -p release/listen/UserData | |
cp rungame.bat release/dedi/rungame.bat | |
cp launch.bat release/dedi/launch.bat | |
cp LICENSE release/dedi/UserData/Mod-License.txt | |
cp LICENSE release/listen/UserData/Mod-License.txt | |
- uses: actions/download-artifact@v4 | |
with: | |
pattern: dedicated-server-* | |
merge-multiple: true | |
path: release/dedi/Mods | |
- uses: actions/download-artifact@v4 | |
with: | |
pattern: listen-server-* | |
merge-multiple: true | |
path: release/listen/Mods | |
- name: Download Updater Plugin | |
uses: robinraju/[email protected] | |
with: | |
repository: "data-bomb/MelonLoader_SilicaUpdater" | |
latest: true | |
fileName: "*.dll" | |
tarBall: false | |
zipBall: false | |
- name: Download Discord Status Plugin | |
uses: robinraju/[email protected] | |
with: | |
repository: "data-bomb/MelonLoader_SilicaDiscordRP" | |
latest: true | |
fileName: "*.dll" | |
tarBall: false | |
zipBall: false | |
- name: Move Plugins into Release | |
run: | | |
mv Si_ModUpdater.dll release/dedi/Plugins | |
mv Si_ModUpdater_ListenServer.dll release/listen/Plugins/Si_ModUpdater.dll | |
mv Si_DiscordStatus.dll release/dedi/Plugins | |
mv Si_DiscordStatus_ListenServer.dll release/listen/Plugins/Si_DiscordStatus.dll | |
- name: Disable Deprecated Mods | |
run: | | |
# AutoTeamsSelect was addressed with a game update to vote on the next mode | |
mv release/dedi/Mods/Si_AutoTeamsSelect.dll release/dedi/Mods/disabled | |
mv release/listen/Mods/Si_AutoTeamsSelect.dll release/listen/Mods/disabled | |
# FriendlyFireLimits is disabled by default | |
mv release/dedi/Mods/Si_FriendlyFireLimits.dll release/dedi/Mods/disabled | |
mv release/listen/Mods/Si_FriendlyFireLimits.dll release/listen/Mods/disabled | |
# Tech Glitch is disabled because the discrepancy is happening on the server side (not client side) | |
mv release/dedi/Mods/Si_TechGlitch.dll release/dedi/Mods/disabled | |
mv release/listen/Mods/Si_TechGlitch.dll release/listen/Mods/disabled | |
# Better Spawns is disabled because the game added a spawn selection mechanic | |
mv release/dedi/Mods/Si_BetterSpawns.dll release/dedi/Mods/disabled | |
mv release/listen/Mods/Si_BetterSpawns.dll release/listen/Mods/disabled | |
# Webhooks encounters issues/conflicts with the game and the Steam API | |
mv release/dedi/Mods/Si_Webhooks.dll release/dedi/Mods/disabled | |
# Default Units is disabled because a game update for spawn selection prevented this from working properly | |
mv release/dedi/Mods/Si_DefaultUnits.dll release/dedi/Mods/disabled | |
mv release/listen/Mods/Si_DefaultUnits.dll release/listen/Mods/disabled | |
- name: Zip Builds | |
run: | | |
(cd release/dedi && zip -qq -r ../../DedicatedServer-v${{ needs.get-commit-number.outputs.comnum }}-${{ env.GITHUB_SHA_SHORT }}.zip *) | |
(cd release/listen && zip -qq -r ../../ListenServer-v${{ needs.get-commit-number.outputs.comnum }}-${{ env.GITHUB_SHA_SHORT }}.zip *) | |
- name: Print Branch | |
run: echo "current branch_identifier=$(echo ${{needs.branch-ident.outputs.branch_identifier}})" | |
- name: Rename for Beta | |
if: needs.beta-check.outputs.branch_identifier == 'beta' | |
run: | | |
mv DedicatedServer-v${{ needs.get-commit-number.outputs.comnum }}-${{ env.GITHUB_SHA_SHORT }}.zip Beta_DedicatedServer-v${{ needs.get-commit-number.outputs.comnum }}-${{ env.GITHUB_SHA_SHORT }}.zip | |
mv ListenServer-v${{ needs.get-commit-number.outputs.comnum }}-${{ env.GITHUB_SHA_SHORT }}.zip Beta_ListenServer-v${{ needs.get-commit-number.outputs.comnum }}-${{ env.GITHUB_SHA_SHORT }}.zip | |
- name: Main Release | |
uses: softprops/action-gh-release@975c1b265e11dd76618af1c374e7981f9a6ff44a | |
if: needs.beta-check.outputs.branch_identifier == 'main' | |
with: | |
tag_name: v${{ needs.get-commit-number.outputs.comnum }} | |
prerelease: false | |
files: | | |
DedicatedServer-v${{ needs.get-commit-number.outputs.comnum }}-${{ env.GITHUB_SHA_SHORT }}.zip | |
ListenServer-v${{ needs.get-commit-number.outputs.comnum }}-${{ env.GITHUB_SHA_SHORT }}.zip | |
- name: Beta Release | |
uses: softprops/action-gh-release@975c1b265e11dd76618af1c374e7981f9a6ff44a | |
if: needs.beta-check.outputs.branch_identifier == 'beta' | |
with: | |
tag_name: v${{ needs.get-commit-number.outputs.comnum }}-Beta | |
prerelease: true | |
files: | | |
Beta_DedicatedServer-v${{ needs.get-commit-number.outputs.comnum }}-${{ env.GITHUB_SHA_SHORT }}.zip | |
Beta_ListenServer-v${{ needs.get-commit-number.outputs.comnum }}-${{ env.GITHUB_SHA_SHORT }}.zip |