|
| 1 | +name: Promote Shipped APIs |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + pull-requests: write |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 15 | + cancel-in-progress: false |
| 16 | + |
| 17 | +jobs: |
| 18 | + promote-apis: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout code |
| 23 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 24 | + with: |
| 25 | + fetch-depth: 0 |
| 26 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 27 | + |
| 28 | + - name: Configure git |
| 29 | + shell: pwsh |
| 30 | + run: | |
| 31 | + git config user.name "github-actions[bot]" |
| 32 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 33 | +
|
| 34 | + - name: Check for existing PR |
| 35 | + id: check_pr |
| 36 | + shell: pwsh |
| 37 | + env: |
| 38 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 39 | + run: | |
| 40 | + $branch = "${{ github.ref_name }}" |
| 41 | + $prBranch = "promote-shipped-apis-$branch" |
| 42 | + $prNumber = gh pr list --state open --head $prBranch --base $branch --json number --jq '.[0].number' |
| 43 | +
|
| 44 | + if ($prNumber) { |
| 45 | + "pr_exists=true" >> $env:GITHUB_OUTPUT |
| 46 | + "pr_number=$prNumber" >> $env:GITHUB_OUTPUT |
| 47 | + Write-Host "Found existing PR: $prNumber" |
| 48 | + } else { |
| 49 | + "pr_exists=false" >> $env:GITHUB_OUTPUT |
| 50 | + Write-Host "No existing PR found." |
| 51 | + } |
| 52 | +
|
| 53 | + - name: Checkout existing PR branch |
| 54 | + if: steps.check_pr.outputs.pr_exists == 'true' |
| 55 | + shell: pwsh |
| 56 | + run: | |
| 57 | + $branch = "${{ github.ref_name }}" |
| 58 | + $prBranch = "promote-shipped-apis-$branch" |
| 59 | +
|
| 60 | + git fetch origin $prBranch |
| 61 | + git checkout $prBranch |
| 62 | + git merge origin/$branch -m "Merge $branch into promote-shipped-apis branch" |
| 63 | +
|
| 64 | + - name: Run public API promotion script |
| 65 | + shell: pwsh |
| 66 | + run: ./dotnet/eng/scripts/promote-shipped-apis.ps1 |
| 67 | + |
| 68 | + - name: Check for changes |
| 69 | + id: check_changes |
| 70 | + shell: pwsh |
| 71 | + run: | |
| 72 | + $changes = git diff --name-only -- "dotnet/src/**/PublicAPI.*.txt" |
| 73 | + if ($changes) { |
| 74 | + "has_changes=true" >> $env:GITHUB_OUTPUT |
| 75 | + Write-Host "Changed files:" |
| 76 | + Write-Host $changes |
| 77 | + } else { |
| 78 | + "has_changes=false" >> $env:GITHUB_OUTPUT |
| 79 | + Write-Host "No public API promotion changes detected." |
| 80 | + } |
| 81 | +
|
| 82 | + - name: Commit and push changes |
| 83 | + if: steps.check_changes.outputs.has_changes == 'true' |
| 84 | + shell: pwsh |
| 85 | + run: | |
| 86 | + $branch = "${{ github.ref_name }}" |
| 87 | + $prBranch = "promote-shipped-apis-$branch" |
| 88 | +
|
| 89 | + git checkout -B $prBranch |
| 90 | + git add dotnet/src/**/PublicAPI.*.txt |
| 91 | + git commit -m "chore: promote shipped .NET APIs" |
| 92 | + git push --force-with-lease --set-upstream origin $prBranch |
| 93 | +
|
| 94 | + - name: Create new PR |
| 95 | + if: steps.check_pr.outputs.pr_exists == 'false' && steps.check_changes.outputs.has_changes == 'true' |
| 96 | + shell: pwsh |
| 97 | + env: |
| 98 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 99 | + run: | |
| 100 | + $branch = "${{ github.ref_name }}" |
| 101 | + $prBranch = "promote-shipped-apis-$branch" |
| 102 | + $title = "chore: promote shipped .NET APIs for $branch" |
| 103 | + $body = "Automatically promotes entries from PublicAPI.Unshipped.txt to PublicAPI.Shipped.txt for released .NET packages." |
| 104 | +
|
| 105 | + gh pr create --title $title --base $branch --head $prBranch --body $body |
0 commit comments