refactor: remove error log surfacing, normalise DSL naming, misc cleanup #1
This file contains hidden or 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: CD | |
| permissions: | |
| contents: write | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - .github/workflows/cd.yml | |
| - Justfile | |
| - global.json | |
| - package.json | |
| - src/** | |
| jobs: | |
| release: | |
| name: Build and Release | |
| runs-on: ubuntu-latest | |
| env: | |
| CONFIGURATION: Release | |
| SOLUTION: ./src/AspireC4.slnx | |
| PACKAGE_PROJECT: ./src/src/AspireC4/AspireC4.csproj | |
| ARTIFACTS_DIR: ./artifacts/nuget | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - id: release-trigger | |
| name: Determine whether to publish a release | |
| env: | |
| EVENT_NAME: ${{ github.event_name }} | |
| BEFORE_SHA: ${{ github.event.before }} | |
| CURRENT_SHA: ${{ github.sha }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| if [[ "${EVENT_NAME}" == "workflow_dispatch" ]]; then | |
| echo "should_release=true" >> "${GITHUB_OUTPUT}" | |
| exit 0 | |
| fi | |
| if [[ "${BEFORE_SHA}" == "0000000000000000000000000000000000000000" ]]; then | |
| changed_files="$(git show --name-only --pretty='' "${CURRENT_SHA}")" | |
| else | |
| changed_files="$(git diff --name-only "${BEFORE_SHA}" "${CURRENT_SHA}")" | |
| fi | |
| if grep -Fxq "package.json" <<< "${changed_files}"; then | |
| echo "should_release=true" >> "${GITHUB_OUTPUT}" | |
| else | |
| echo "should_release=false" >> "${GITHUB_OUTPUT}" | |
| fi | |
| - id: version | |
| name: Read release version | |
| if: ${{ steps.release-trigger.outputs.should_release == 'true' }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| version="$(node -p "require('./package.json').version")" | |
| echo "value=${version}" >> "${GITHUB_OUTPUT}" | |
| echo "tag=v${version}" >> "${GITHUB_OUTPUT}" | |
| if [[ "${version}" == *-* ]]; then | |
| echo "prerelease=true" >> "${GITHUB_OUTPUT}" | |
| else | |
| echo "prerelease=false" >> "${GITHUB_OUTPUT}" | |
| fi | |
| - name: Block duplicate version | |
| if: ${{ steps.release-trigger.outputs.should_release == 'true' }} | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| RELEASE_TAG: ${{ steps.version.outputs.tag }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| if git ls-remote --exit-code --tags origin "refs/tags/${RELEASE_TAG}" > /dev/null 2>&1; then | |
| echo "::error::Tag ${RELEASE_TAG} already exists on origin. Refusing to replace an existing release version." | |
| exit 1 | |
| fi | |
| release_status="$( | |
| curl -sS \ | |
| -o release.json \ | |
| -w "%{http_code}" \ | |
| -H "Authorization: Bearer ${GITHUB_TOKEN}" \ | |
| -H "Accept: application/vnd.github+json" \ | |
| "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/tags/${RELEASE_TAG}" | |
| )" | |
| if [[ "${release_status}" == "200" ]]; then | |
| echo "::error::Release ${RELEASE_TAG} already exists. Refusing to replace an existing release version." | |
| cat release.json | |
| exit 1 | |
| fi | |
| if [[ "${release_status}" != "404" ]]; then | |
| echo "::error::Unexpected GitHub API response while checking ${RELEASE_TAG} (HTTP ${release_status})." | |
| cat release.json | |
| exit 1 | |
| fi | |
| rm -f release.json | |
| - name: Set up .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| global-json-file: ./global.json | |
| - name: Restore dotnet tools | |
| run: dotnet tool restore | |
| - name: CSharpier format check | |
| run: dotnet csharpier check src | |
| - name: Restore solution | |
| run: dotnet restore ${{ env.SOLUTION }} | |
| - name: Build solution | |
| run: dotnet build ${{ env.SOLUTION }} --no-restore --configuration ${{ env.CONFIGURATION }} | |
| - name: Run unit tests | |
| run: dotnet test --project src/tests/AspireC4.UnitTests --no-build --verbosity normal --configuration ${{ env.CONFIGURATION }} | |
| - name: Run integration tests | |
| run: dotnet test --project src/tests/AspireC4.IntegrationTests --no-build --verbosity normal --configuration ${{ env.CONFIGURATION }} | |
| - name: Pack NuGet artifacts | |
| if: ${{ steps.release-trigger.outputs.should_release == 'true' }} | |
| env: | |
| PACKAGE_VERSION: ${{ steps.version.outputs.value }} | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| mkdir -p "${ARTIFACTS_DIR}" | |
| dotnet pack "${PACKAGE_PROJECT}" \ | |
| --configuration "${CONFIGURATION}" \ | |
| --no-build \ | |
| --output "${ARTIFACTS_DIR}" \ | |
| --include-symbols \ | |
| "/p:Version=${PACKAGE_VERSION}" \ | |
| "/p:RepositoryBranch=${GITHUB_REF_NAME}" \ | |
| "/p:RepositoryCommit=${GITHUB_SHA}" \ | |
| "/p:COPYRIGHT_YEAR=$(date -u +%Y)" | |
| - name: Create GitHub release | |
| if: ${{ steps.release-trigger.outputs.should_release == 'true' }} | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.version.outputs.tag }} | |
| name: ${{ steps.version.outputs.tag }} | |
| target_commitish: ${{ github.sha }} | |
| generate_release_notes: true | |
| prerelease: ${{ steps.version.outputs.prerelease }} | |
| fail_on_unmatched_files: true | |
| files: | | |
| ./artifacts/nuget/*.nupkg | |
| ./artifacts/nuget/*.snupkg | |
| - name: Skip release publish | |
| if: ${{ steps.release-trigger.outputs.should_release != 'true' }} | |
| run: echo "package.json did not change on this push, so release publishing was skipped." |