Build and test #188
Workflow file for this run
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
name: build | |
run-name: Build and test | |
on: | |
pull_request: | |
types: [opened, reopened, synchronize] | |
merge_group: | |
types: [checks_requested] | |
push: | |
branches: | |
- main | |
release: | |
types: [published] | |
jobs: | |
formatting: | |
name: Check formatting | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@6bd8b7f7774af54e05809fcc5431931b3eb1ddee # v4.0.1 | |
with: | |
dotnet-version: 8.0.303 | |
- name: Install tools | |
run: dotnet tool restore | |
- name: Check formatting | |
run: dotnet csharpier --check . | |
coverage: | |
name: Check code coverage | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@6bd8b7f7774af54e05809fcc5431931b3eb1ddee # v4.0.1 | |
with: | |
dotnet-version: 8.0.303 | |
- name: Run tests | |
run: dotnet test -c Debug --collect:"XPlat Code Coverage" --settings coverlet.runsettings ArchUnitNETTests/ | |
- name: Upload coverage reports to Codecov | |
uses: codecov/[email protected] | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
run-tests: | |
name: Run tests | |
strategy: | |
matrix: | |
os: [ubuntu-latest, windows-latest] | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@6bd8b7f7774af54e05809fcc5431931b3eb1ddee # v4.0.1 | |
with: | |
dotnet-version: 8.0.303 | |
- name: Run tests | |
run: dotnet test -c Debug | |
publish-docs: | |
name: Publish documentation | |
runs-on: ubuntu-latest | |
needs: | |
- formatting | |
- coverage | |
- run-tests | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
- name: Setup doxygen | |
run: sudo apt-get install doxygen graphviz | |
- name: Create temporary directory | |
run: | | |
tmpdir=$(mktemp -d -p "$GITHUB_WORKSPACE") | |
mkdir -p $tmpdir | |
relative_path=$(realpath --relative-to="$GITHUB_WORKSPACE" "$tmpdir") | |
echo "Created temporary directory $tmpdir ($relative_path relative to $GITHUB_WORKSPACE)" | |
echo "DOCS_TEMP_DIR=$relative_path" >> "$GITHUB_ENV" | |
if [[ "$GITHUB_REF" =~ ^"refs/tags/"[0-9]+.[0-9]+.[0-9]+$ ]]; then | |
echo "DOCS_TEMP_DIR_SUBPATH=stable" >> "$GITHUB_ENV" | |
else | |
if [[ "$GITHUB_REF" =~ ^"refs/tags/"[0-9]+.[0-9]+.[0-9]+-[a-z]+.[0-9]+$ ]]; then | |
echo "DOCS_TEMP_DIR_SUBPATH=preview" >> "$GITHUB_ENV" | |
else | |
echo "DOCS_TEMP_DIR_SUBPATH=latest" >> "$GITHUB_ENV" | |
fi | |
fi | |
- name: Checkout gh-pages branch | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
with: | |
ref: gh-pages | |
path: ${{ env.DOCS_TEMP_DIR }} | |
- name: Generate documentation | |
working-directory: ${{ env.DOCS_TEMP_DIR }}/${{ env.DOCS_TEMP_DIR_SUBPATH }} | |
run: | | |
rm -rf '*' | |
doxygen "$GITHUB_WORKSPACE/documentation/Doxyfile" | |
touch .nojekyll | |
- name: Check release conditions | |
run: | | |
if [[ "$GITHUB_REF" =~ ^"refs/tags/"[0-9]+.[0-9]+.[0-9]+(-[a-z]+.[0-9]+)?|"refs/heads/main"$ ]]; then | |
echo "CREATE_RELEASE=true" >> "$GITHUB_ENV" | |
else | |
echo "CREATE_RELEASE=false" >> "$GITHUB_ENV" | |
fi | |
- name: Commit and push changes | |
if: env.CREATE_RELEASE == 'true' | |
working-directory: ${{ env.DOCS_TEMP_DIR }} | |
run: | | |
git config --global user.name "GitHub Actions" | |
git config --global user.email "[email protected]" | |
git add -A | |
if [[ "$(git status --porcelain)" ]]; then | |
git commit -m "Update documentation for $GITHUB_REF_NAME" | |
git push | |
else | |
echo "No changes to commit" | |
fi | |
- name: Update readthedocs preview | |
if: env.CREATE_RELEASE == 'true' && env.DOCS_TEMP_DIR_SUBPATH == 'preview' | |
run: | | |
git fetch origin preview | |
git checkout preview | |
git reset --hard "$GITHUB_REF" | |
git push origin --force-with-lease | |
publish-packages: | |
name: Publish packages | |
if: github.event_name == 'release' | |
runs-on: windows-latest | |
environment: deploy | |
needs: | |
- formatting | |
- coverage | |
- run-tests | |
steps: | |
- name: Checkout | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@6bd8b7f7774af54e05809fcc5431931b3eb1ddee # v4.0.1 | |
with: | |
dotnet-version: 8.0.303 | |
- name: Build | |
run: dotnet build -c Release | |
- name: Pack | |
run: | | |
$semver = "$env:GITHUB_REF_NAME" | |
if ($semver -match '^(\d+)\.(\d+)\.\d+') { | |
$major = $matches[1] | |
$minor = $matches[2] | |
$packageVersion = "$env:GITHUB_REF_NAME" | |
$assemblyVersion = "$major.$minor.$env:GITHUB_RUN_NUMBER.0" | |
Write-Host "Package version: $packageVersion" | |
Write-Host "Assembly version: $assemblyVersion" | |
dotnet pack -c Release --output nupkgs -p:PackageVersion=$packageVersion -p:AssemblyVersion=$assemblyVersion | |
} else { | |
throw "Invalid semver format" | |
} | |
- name: Check release conditions | |
shell: bash | |
run: | | |
if [[ "$GITHUB_REF" =~ ^"refs/tags/"[0-9]+.[0-9]+.[0-9]+(-[a-z]+.[0-9]+)?|"refs/heads/main"$ ]]; then | |
echo "CREATE_RELEASE=true" >> "$GITHUB_ENV" | |
else | |
echo "CREATE_RELEASE=false" >> "$GITHUB_ENV" | |
fi | |
- name: Push | |
if: env.CREATE_RELEASE == 'true' | |
run: dotnet nuget push nupkgs/*.nupkg --source https://api.nuget.org/v3/index.json --api-key "$env:NUGET_API_KEY" | |
env: | |
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} |