Skip to content

Commit

Permalink
refactor: Build/Test Workflows
Browse files Browse the repository at this point in the history
This breaks apart our build/test workflows to make them reusable. With the
aim of being able to reduce deplication, improve maintainability, and efficiency
of how the workflows run.
  • Loading branch information
techman83 committed May 4, 2024
1 parent 8189e5a commit e89bf81
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 81 deletions.
96 changes: 15 additions & 81 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,98 +4,32 @@ on:
push:
branches:
- master
pull_request:
types:
- opened
- synchronize
- reopened
workflow_call:
inputs:
configuration:
type: string
default: Debug

jobs:
build:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
mono:
- latest
- '6.12'
- '6.10'
- '6.8'
configuration:
- Debug
- Release

container:
image: mono:${{ matrix.mono }}

steps:
- name: Adding HTTPS support to APT for old Mono images
run: |
apt-get update || true
apt-get install -y apt-transport-https
- name: Installing checkout/build dependencies
run: apt-get update && apt-get install -y git
- uses: actions/checkout@v4

- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: '7'
- name: Install runtime dependencies
run: apt-get install -y xvfb
- name: Restore cache for _build/tools
uses: actions/cache@v3
with:
path: _build/tools
key: build-tools-${{ hashFiles('build', 'build.ps1', 'build.cake') }}
- name: Restore cache for _build/cake
uses: actions/cache@v3
with:
path: _build/cake
key: build-cake-${{ hashFiles('build.cake') }}
- name: Restore cache for _build/lib/nuget
uses: actions/cache@v3
with:
path: _build/lib/nuget
key: nuget-oldref-modules-${{ hashFiles('**/packages.config') }}-${{ hashFiles('**/*.csproj') }}
- name: Restore cache for ~/.nuget/packages
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: nuget-packref-modules-${{ hashFiles('**/packages.config') }}-${{ hashFiles('**/*.csproj') }}

- name: Build ckan.exe and netkan.exe
run: ./build --configuration=${{ matrix.configuration}}
run: ./build --configuration=${{ inputs.configuration }}
- name: Run tests
run: xvfb-run ./build test+only --configuration=${{ matrix.configuration }} --where="Category!=FlakyNetwork"
- name: Run inflator container smoke test
run: |
cd _build
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
docker build --tag inflator --file ../Dockerfile.netkan .
docker run --rm --name inflator --entrypoint /bin/bash inflator -c "
mono netkan.exe https://raw.githubusercontent.com/KSP-CKAN/NetKAN/master/NetKAN/ZeroMiniAVC.netkan
"
if: matrix.configuration == 'release'

- name: Upload ckan.exe artifact
uses: actions/upload-artifact@v3
run: xvfb-run ./build test+only --configuration=${{ inputs.configuration }} --where="Category!=FlakyNetwork"
- uses: actions/upload-artifact@v4
with:
name: ckan.exe
path: _build/repack/Release/ckan.exe
name: ${{ inputs.configuration }}-repack-unsigned
path: _build/repack/
retention-days: 7
if: matrix.configuration == 'release' && matrix.mono == 'latest' && github.event_name == 'pull_request'

- name: Send Discord Notification
env:
JOB_STATUS: ${{ job.status }}
WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK }}
HOOK_OS_NAME: ${{ runner.os }}
WORKFLOW_NAME: ${{ github.workflow }}
if: ${{ failure() && env.WEBHOOK_URL }}
run: |
git clone https://github.com/DiscordHooks/github-actions-discord-webhook.git webhook
bash webhook/send.sh $JOB_STATUS $WEBHOOK_URL
shell: bash
- uses: actions/upload-artifact@v4
with:
name: ${{ inputs.configuration }}-out
path: _build/out/
retention-days: 1
97 changes: 97 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Build CKAN + NetKAN

on:
pull_request:
types:
- opened
- synchronize
- reopened

jobs:
build-debug:
uses: ./.github/workflows/build.yml
test-mono:
needs: build-debug
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
mono:
- latest
- '6.12'
- '6.10'
- '6.8'
container:
image: mono:${{ matrix.mono }}
steps:
- name: Adding HTTPS support to APT for old Mono images
run: |
apt-get update || true
apt-get install -y apt-transport-https
- name: Installing checkout/build dependencies
run: apt-get update && apt-get install -y git
- uses: actions/checkout@v4
- name: Install runtime dependencies
run: apt-get install -y xvfb
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: '7'
- uses: actions/download-artifact@v4
with:
name: Debug-out
path: _build/out/
- uses: actions/download-artifact@v4
with:
name: Debug-repack-unsigned
path: _build/repack/
- name: Run tests
run: xvfb-run ./build test+only --configuration=Debug --where="Category!=FlakyNetwork"

build-release:
uses: ./.github/workflows/build.yml
with:
configuration: Release
smoke-test-release:
needs: build-release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: Release-repack-unsigned
path: _build/repack/
- name: Run inflator container smoke test
working-directory: _build
run: |
cp -v repack/Release/netkan.exe .
docker build --tag inflator --file ../Dockerfile.netkan .
docker run --rm --name inflator --entrypoint /bin/bash inflator -c "
mono netkan.exe https://raw.githubusercontent.com/KSP-CKAN/NetKAN/master/NetKAN/ZeroMiniAVC.netkan
"
- name: Upload ckan.exe artifact
uses: actions/upload-artifact@v3
with:
name: ckan.exe
path: _build/repack/Release/ckan.exe
retention-days: 7
if: github.event_name == 'pull_request'

notify:
needs:
- test-mono
- smoke-test-release
runs-on: ubuntu-latest
if: failure()
steps:
- name: Send Discord Notification
env:
JOB_STATUS: failure
WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK }}
HOOK_OS_NAME: ${{ runner.os }}
WORKFLOW_NAME: ${{ github.workflow }}
if: env.WEBHOOK_URL
run: |
git clone https://github.com/DiscordHooks/github-actions-discord-webhook.git webhook
bash webhook/send.sh $JOB_STATUS $WEBHOOK_URL
shell: bash

0 comments on commit e89bf81

Please sign in to comment.