.NET build #88
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: .NET build | |
on: | |
#push: | |
# branches: [ "main" ] | |
#pull_request: | |
# branches: [ "main" ] | |
workflow_dispatch: | |
# keep consistent with workflow_call | |
inputs: | |
artifact_name: | |
required: false | |
type: string | |
default: 'nupkg' | |
release_ver: | |
description: | | |
Leave empty to skip creating release branch. | |
NOTE: 'release' prefix is automatically added. | |
required: false | |
type: string | |
default: '' | |
# make this action reusable | |
workflow_call: | |
inputs: | |
artifact_name: | |
required: false | |
type: string | |
default: 'nupkg' | |
release_ver: | |
description: | | |
Leave empty to skip creating release branch. | |
NOTE: 'release' prefix is automatically added. | |
required: false | |
type: string | |
default: '' | |
outputs: | |
artifact_name: | |
value: ${{ inputs.artifact_name }} | |
release_ver: | |
value: ${{ inputs.release_ver }} | |
env: | |
unity_folder: 'SatorImaging.StaticMemberAnalyzer.Unity' # no spaces! | |
test_csproj: 'StaticMemberAnalyzer.Test/SatorImaging.StaticMemberAnalyzer.Test.csproj' | |
GH_TOKEN: ${{ github.token }} # for github CLI | |
docsgen_file_name: 'RULES.md' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
dotnet-version: [ '8.0.x' ] | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup .NET ${{ matrix.dotnet-version }} | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: ${{ matrix.dotnet-version }} | |
##cache: true | |
- name: Restore dependencies | |
run: | | |
cd src | |
dotnet restore -p:DontReferenceItself=true # required to avoid cyclic ref error | |
- name: Build | |
run: | | |
cd src | |
# required to enable deterministic build --> -p:ContinuousIntegrationBuild=true | |
# it seems that hash is calculated based on the whole git directory contents | |
# ex: including github actions yaml files | |
dotnet build -c Release --no-restore -p:ContinuousIntegrationBuild=true -p:DontReferenceItself=true | |
- name: Test | |
run: | | |
cd src | |
dotnet test ${{ env.test_csproj }} -c Release --no-build --verbosity normal -p:DontReferenceItself=true | |
- name: Upload | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ inputs.artifact_name }} | |
path: 'src/**/Release/*.nupkg' | |
- name: git setup | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
# to omit `--set-upstream origin` for git push | |
git config --global --add --bool push.autoSetupRemote true | |
git fetch --all | |
- name: docsgen | |
run: | | |
cd src/DocsGen | |
dotnet run -c Release "../StaticMemberAnalyzer.Analysis/Resources.resx" "../../${{ env.docsgen_file_name }}" | |
# commit docsgen result | |
cd ../.. | |
git add ${{ env.docsgen_file_name }} | |
git commit -m "[bot] ${{ env.docsgen_file_name }}" || true | |
git push || true | |
# actions/cache can be used to share data across jobs | |
- name: Commit for Unity | |
if: ${{ inputs.release_ver != '' }} | |
continue-on-error: false | |
run: | | |
ls -al | |
### no way! no create-remote-if-not-exists option!! | |
git switch release/${{ inputs.release_ver }} || git switch -c release/${{ inputs.release_ver }} | |
git pull || true | |
git branch -vv | |
# upload compiled assembly | |
# trailing slash is required to sync (copy) contents instead of directory | |
rsync -avr --existing --checksum src/StaticMemberAnalyzer.Package/bin/Release/*/ ${{ env.unity_folder }} | |
git add --update --ignore-removal ${{ env.unity_folder }} | |
### try push and create PR if any changes otherwise exit successfully | |
git commit -m "[bot] Precompiled Assembly for Unity" || true | |
git push || true | |
gh pr create -B main -t 'release/${{ inputs.release_ver }}' -b '' || true |