|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: tests-refs/heads/${{ github.event.repository.default_branch }} |
| 10 | + cancel-in-progress: true |
| 11 | + |
| 12 | +jobs: |
| 13 | + release: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + contents: write |
| 17 | + |
| 18 | + steps: |
| 19 | + # Tag validation runs before checkout -- no workspace is needed for this check. |
| 20 | + # The glob above is intentionally loose; this step is the authoritative gate. |
| 21 | + - name: Validate tag format |
| 22 | + shell: bash |
| 23 | + run: | |
| 24 | + if [[ ! "${GITHUB_REF_NAME}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 25 | + echo "Tag '${GITHUB_REF_NAME}' does not match required format vX.Y.Z" |
| 26 | + exit 1 |
| 27 | + fi |
| 28 | +
|
| 29 | + - name: Checkout |
| 30 | + uses: actions/checkout@v4 |
| 31 | + with: |
| 32 | + fetch-depth: 0 |
| 33 | + |
| 34 | + - name: Install Pester and PSScriptAnalyzer |
| 35 | + run: | |
| 36 | + pwsh -Command "Install-Module Pester -MinimumVersion 5.7.0 -Force -Scope CurrentUser" |
| 37 | + pwsh -Command "Install-Module PSScriptAnalyzer -Force -Scope CurrentUser" |
| 38 | +
|
| 39 | + - name: Run tests |
| 40 | + shell: pwsh |
| 41 | + env: |
| 42 | + TERM: dumb |
| 43 | + NO_COLOR: "1" |
| 44 | + run: | |
| 45 | + $PSStyle.OutputRendering = 'PlainText' |
| 46 | + ./tests/run-tests.ps1 |
| 47 | +
|
| 48 | + - name: Extract version from tag |
| 49 | + shell: bash |
| 50 | + run: | |
| 51 | + VERSION="${GITHUB_REF_NAME#v}" |
| 52 | + echo "VERSION=${VERSION}" >> "$GITHUB_ENV" |
| 53 | +
|
| 54 | + - name: Populate release notes |
| 55 | + shell: bash |
| 56 | + run: | |
| 57 | + if [[ ! -f .github/RELEASE_TEMPLATE.md ]]; then |
| 58 | + echo "ERROR: Missing .github/RELEASE_TEMPLATE.md" |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | +
|
| 62 | + CHANGELOG_SECTION=$(awk '/^## \['"${VERSION}"'\]/{found=1; next} /^## \[/{if(found) exit} found' CHANGELOG.md) |
| 63 | +
|
| 64 | + if [[ -z "${CHANGELOG_SECTION}" ]]; then |
| 65 | + echo "ERROR: No entry for version ${VERSION} found in CHANGELOG.md" |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | +
|
| 69 | + sed "s/vX\.Y\.Z/v${VERSION}/g; s/X\.Y\.Z/${VERSION}/g" \ |
| 70 | + .github/RELEASE_TEMPLATE.md > release-notes.md |
| 71 | +
|
| 72 | + printf '\n---\n\n# Change Log\n\n%s\n' "${CHANGELOG_SECTION}" >> release-notes.md |
| 73 | +
|
| 74 | + - name: Create GitHub release |
| 75 | + env: |
| 76 | + GH_TOKEN: ${{ github.token }} |
| 77 | + run: | |
| 78 | + REPO_NAME="${GITHUB_REPOSITORY##*/}" |
| 79 | + gh release create "${GITHUB_REF_NAME}" \ |
| 80 | + --title "${REPO_NAME} v${VERSION}" \ |
| 81 | + --notes-file release-notes.md \ |
| 82 | + source/delphi-dccbuild.ps1 |
0 commit comments