Merge branch 'main' of https://github.com/data-bomb/Silica #4
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" ] | |
paths: | |
- '**/Si_*/**' | |
- '!*.md' | |
- '!*.json' | |
env: | |
BUILD_TYPE: Release | |
jobs: | |
get-commit-number: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
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: | |
- uses: actions/checkout@v3 | |
- uses: dorny/paths-filter@v2 | |
id: checkAdminMod | |
with: | |
filters: | | |
admin-updated: | |
- 'Si_AdminMod/**' | |
# 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 ] | |
if: needs.find-if-nuget-update-is-needed.outputs.admin-updated == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Setup .NET SDK | |
uses: actions/setup-dotnet@v3 | |
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 ] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- 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 | |
- uses: actions/checkout@v3 | |
- 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@v3 | |
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}} | |
- name: Make output paths | |
run: | | |
cd ${{ env.START_DIR }} | |
mkdir -p dedi/Mods | |
mkdir -p listen/Mods | |
mkdir -p dedi/Mods/disabled | |
mkdir -p listen/Mods/disabled | |
mkdir -p dedi/UserData | |
mkdir -p listen/UserData | |
cp LICENSE dedi/UserData/Mod-License.txt | |
cp LICENSE listen/UserData/Mod-License.txt | |
cp ${{ env.START_DIR }}/${{ matrix.path }}/bin/${{env.BUILD_TYPE}}/netstandard2.1/*.dll dedi/Mods | |
cp ${{ env.START_DIR }}/${{ matrix.path }}/bin/${{env.BUILD_TYPE}}/net6.0/*.dll listen/Mods | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ matrix.path }}-build-${{ env.GITHUB_SHA_SHORT }} | |
path: ${{ matrix.path }}/bin/${{env.BUILD_TYPE}}/**/*.dll | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: dedicated-server-${{ env.GITHUB_SHA_SHORT }} | |
path: ${{ env.START_DIR }}/dedi | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: listen-server-${{ env.GITHUB_SHA_SHORT }} | |
path: ${{ env.START_DIR }}/listen | |
publish: | |
if: github.event_name == 'push' && ${{ !failure() && !cancelled() }} | |
permissions: | |
contents: write | |
needs: [ get-commit-number, build, fanout ] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Prepare env | |
shell: bash | |
run: echo "GITHUB_SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV | |
- name: Make output paths | |
run: | | |
mkdir -p release/dedi | |
mkdir -p release/listen | |
- uses: actions/download-artifact@v3 | |
with: | |
name: dedicated-server-${{ env.GITHUB_SHA_SHORT }} | |
path: release/dedi | |
- uses: actions/download-artifact@v3 | |
with: | |
name: listen-server-${{ env.GITHUB_SHA_SHORT }} | |
path: release/listen | |
- 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: Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: v${{ needs.get-commit-number.outputs.comnum }} | |
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 |