BililiveRecorder/.github/workflows/build.yml

143 lines
4.6 KiB
YAML
Raw Normal View History

2021-02-26 21:57:10 +08:00
name: Build and Test
on:
push:
pull_request:
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
2021-05-02 22:52:52 +08:00
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
2021-02-26 21:57:10 +08:00
jobs:
test:
strategy:
matrix:
os: [windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
2021-05-02 22:52:52 +08:00
- name: Cache Nuget Packages
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
2021-02-26 21:57:10 +08:00
- name: Restore Packages
run: dotnet restore -v m
- name: Run Tests
run: dotnet test -v m
build_wpf:
needs: test
strategy:
matrix:
build_configuration: [Debug, Release]
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
2021-05-02 22:52:52 +08:00
- name: Cache Nuget Packages
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
2021-02-26 22:30:10 +08:00
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.0.2
2021-02-26 21:57:10 +08:00
- name: Restore Packages
run: nuget restore -Verbosity quiet
- name: Build WPF
run: msbuild /nologo /v:m /p:Configuration="${{ matrix.build_configuration }}"
- name: Upload Artifacts
uses: actions/upload-artifact@v2
with:
name: WPF-${{ matrix.build_configuration }}
path: BililiveRecorder.WPF/bin/${{ matrix.build_configuration }}
build_cli:
needs: test
strategy:
matrix:
rid: [any, linux-arm, linux-arm64, linux-x64, osx-x64, win-x64]
build_configuration: [Debug, Release]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
2021-05-02 22:52:52 +08:00
- name: Cache Nuget Packages
uses: actions/cache@v2
with:
path: ${{ github.workspace }}/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
2021-02-26 21:57:10 +08:00
- name: Restore Packages
run: dotnet restore -v m
- name: Build CLI
if: ${{ matrix.rid == 'any' }}
2021-02-26 22:25:35 +08:00
run: dotnet publish -c ${{ matrix.build_configuration }} BililiveRecorder.Cli/BililiveRecorder.Cli.csproj
2021-02-26 21:57:10 +08:00
- name: Build CLI
if: ${{ matrix.rid != 'any' }}
2021-02-26 22:25:35 +08:00
run: dotnet publish -c ${{ matrix.build_configuration }} -r ${{ matrix.rid }} BililiveRecorder.Cli/BililiveRecorder.Cli.csproj
2021-02-26 21:57:10 +08:00
- name: Upload Artifacts
uses: actions/upload-artifact@v2
with:
name: CLI-${{ matrix.rid }}-${{ matrix.build_configuration }}
2021-02-26 22:41:03 +08:00
path: BililiveRecorder.Cli/publish/${{ matrix.rid }}
build_docker:
needs: test
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
2021-06-17 23:41:41 +08:00
- name: Build CLI
run: dotnet build -c Release -o ./BililiveRecorder.Cli/bin/docker_out BililiveRecorder.Cli/BililiveRecorder.Cli.csproj
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
2021-06-17 23:41:41 +08:00
file: ./Dockerfile.GitHubActions
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}