|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + repository_dispatch: |
| 5 | + types: [openapi-updated] |
| 6 | + schedule: |
| 7 | + - cron: '0 6 * * *' |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + version_bump: |
| 11 | + description: 'patch | minor | major' |
| 12 | + required: false |
| 13 | + default: 'patch' |
| 14 | + |
| 15 | +jobs: |
| 16 | + release: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + environment: release |
| 19 | + permissions: |
| 20 | + contents: write |
| 21 | + id-token: write |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v6 |
| 24 | + with: |
| 25 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 26 | + |
| 27 | + - uses: actions/setup-dotnet@v5 |
| 28 | + with: |
| 29 | + dotnet-version: | |
| 30 | + 8.0.x |
| 31 | + 9.0.x |
| 32 | +
|
| 33 | + - name: Install Kiota |
| 34 | + run: | |
| 35 | + dotnet tool install --global Microsoft.OpenApi.Kiota --version 1.32.2 |
| 36 | + echo "$HOME/.dotnet/tools" >> "$GITHUB_PATH" |
| 37 | +
|
| 38 | + - name: Regenerate from live spec |
| 39 | + run: dotnet run --project tools/RoxyDevTools -- generate |
| 40 | + |
| 41 | + - name: Check if spec changed |
| 42 | + id: diff |
| 43 | + run: | |
| 44 | + if git diff --quiet specs/openapi.json src/Generated; then |
| 45 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 46 | + else |
| 47 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 48 | + fi |
| 49 | +
|
| 50 | + - name: Build |
| 51 | + if: steps.diff.outputs.changed == 'true' || github.event_name == 'workflow_dispatch' |
| 52 | + run: dotnet build -c Release |
| 53 | + |
| 54 | + - name: Test |
| 55 | + if: steps.diff.outputs.changed == 'true' || github.event_name == 'workflow_dispatch' |
| 56 | + run: dotnet test -c Release --no-build |
| 57 | + env: |
| 58 | + ROXY_API_KEY: ${{ secrets.ROXY_API_KEY }} |
| 59 | + |
| 60 | + - name: Bump version in src/RoxyApi.csproj |
| 61 | + id: bump |
| 62 | + if: steps.diff.outputs.changed == 'true' || github.event_name == 'workflow_dispatch' |
| 63 | + run: | |
| 64 | + python3 - <<'PY' |
| 65 | + import os, re |
| 66 | + bump = "${{ github.event.inputs.version_bump || 'patch' }}" |
| 67 | + path = "src/RoxyApi.csproj" |
| 68 | + text = open(path).read() |
| 69 | + cur = re.search(r"<Version>(.+?)</Version>", text).group(1) |
| 70 | + major, minor, patch = (int(x) for x in cur.split(".")) |
| 71 | + if bump == "major": major, minor, patch = major + 1, 0, 0 |
| 72 | + elif bump == "minor": minor, patch = minor + 1, 0 |
| 73 | + else: patch += 1 |
| 74 | + new = f"{major}.{minor}.{patch}" |
| 75 | + open(path, "w").write(text.replace(f"<Version>{cur}</Version>", f"<Version>{new}</Version>", 1)) |
| 76 | + with open(os.environ["GITHUB_OUTPUT"], "a") as f: |
| 77 | + f.write(f"version={new}\n") |
| 78 | + print(f"Bumped {cur} -> {new} ({bump})") |
| 79 | + PY |
| 80 | +
|
| 81 | + - name: Pack |
| 82 | + if: steps.diff.outputs.changed == 'true' || github.event_name == 'workflow_dispatch' |
| 83 | + run: dotnet pack src/RoxyApi.csproj -c Release -o artifacts |
| 84 | + |
| 85 | + - name: NuGet login (OIDC, short-lived API key) |
| 86 | + id: login |
| 87 | + if: steps.diff.outputs.changed == 'true' || github.event_name == 'workflow_dispatch' |
| 88 | + uses: NuGet/login@v1 |
| 89 | + with: |
| 90 | + user: ${{ secrets.NUGET_USER }} |
| 91 | + |
| 92 | + - name: Push to NuGet |
| 93 | + if: steps.diff.outputs.changed == 'true' || github.event_name == 'workflow_dispatch' |
| 94 | + run: dotnet nuget push "artifacts/*.nupkg" --api-key "${{ steps.login.outputs.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate |
| 95 | + |
| 96 | + - name: Commit, tag, push |
| 97 | + if: steps.diff.outputs.changed == 'true' || github.event_name == 'workflow_dispatch' |
| 98 | + run: | |
| 99 | + git config user.name "github-actions[bot]" |
| 100 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 101 | + VERSION=${{ steps.bump.outputs.version }} |
| 102 | + git add specs/openapi.json src/ README.md AGENTS.md docs/llms-full.txt tests/RoxyApi.Tests/Generated |
| 103 | + git commit -m "release: v$VERSION" |
| 104 | + git tag "v$VERSION" |
| 105 | + git push --follow-tags |
| 106 | +
|
| 107 | + - name: Create GitHub release |
| 108 | + if: steps.diff.outputs.changed == 'true' || github.event_name == 'workflow_dispatch' |
| 109 | + uses: softprops/action-gh-release@v3 |
| 110 | + with: |
| 111 | + tag_name: v${{ steps.bump.outputs.version }} |
| 112 | + generate_release_notes: true |
| 113 | + make_latest: 'true' |
| 114 | + files: artifacts/*.nupkg |
0 commit comments