Skip to content

Commit 9368efd

Browse files
committed
ci: adds a workflow to automatically promote unshipped APIs
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
1 parent 4de55a4 commit 9368efd

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
name: Promote Shipped APIs
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- support/v2
8+
9+
jobs:
10+
promote-apis:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
pull-requests: write
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v6
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Configure git
23+
run: |
24+
git config --global user.name "github-actions[bot]"
25+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
26+
27+
- name: Check for existing PR
28+
id: check_pr
29+
shell: pwsh
30+
env:
31+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
run: |
33+
$branch = "${{ github.ref_name }}"
34+
$prs = gh pr list --state open --head "promote-shipped-apis-$branch" --json number --jq '.[0].number' 2>$null
35+
if ($prs) {
36+
echo "pr_number=$prs" >> $env:GITHUB_OUTPUT
37+
echo "pr_exists=true" >> $env:GITHUB_OUTPUT
38+
Write-Host "Found existing PR: $prs"
39+
} else {
40+
echo "pr_exists=false" >> $env:GITHUB_OUTPUT
41+
Write-Host "No existing PR found"
42+
}
43+
44+
- name: Checkout existing PR branch
45+
if: steps.check_pr.outputs.pr_exists == 'true'
46+
shell: pwsh
47+
run: |
48+
$branch = "${{ github.ref_name }}"
49+
$prBranch = "promote-shipped-apis-$branch"
50+
51+
git fetch origin
52+
git checkout $prBranch
53+
54+
- name: Merge trigger branch into PR branch
55+
if: steps.check_pr.outputs.pr_exists == 'true'
56+
shell: pwsh
57+
run: |
58+
$branch = "${{ github.ref_name }}"
59+
git merge origin/$branch -m "Merge $branch into promote branch"
60+
61+
- name: Run promote unshipped script
62+
shell: pwsh
63+
run: |
64+
& .\scripts\promoteUnshipped.ps1
65+
66+
- name: Check for changes
67+
id: check_changes
68+
shell: pwsh
69+
run: |
70+
$changes = git diff --name-only -- "*Shipped.txt"
71+
if ($changes) {
72+
echo "has_changes=true" >> $env:GITHUB_OUTPUT
73+
Write-Host "Changed files: $changes"
74+
} else {
75+
echo "has_changes=false" >> $env:GITHUB_OUTPUT
76+
Write-Host "No changes detected"
77+
}
78+
79+
- name: Commit and push changes
80+
if: steps.check_changes.outputs.has_changes == 'true'
81+
shell: pwsh
82+
run: |
83+
git add *Shipped.txt
84+
git commit -m "chore: promote shipped APIs"
85+
86+
$branch = "${{ github.ref_name }}"
87+
$prBranch = "promote-shipped-apis-$branch"
88+
git push origin $prBranch
89+
90+
- name: Create new PR
91+
if: steps.check_pr.outputs.pr_exists == 'false' && steps.check_changes.outputs.has_changes == 'true'
92+
shell: pwsh
93+
env:
94+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95+
run: |
96+
$branch = "${{ github.ref_name }}"
97+
$prBranch = "promote-shipped-apis-$branch"
98+
$title = "automatic promotion of shipped APIs for $branch"
99+
100+
git checkout -b $prBranch
101+
git push origin $prBranch
102+
103+
gh pr create --title "$title" --base "$branch" --head "$prBranch" --body "Automatically promotes unshipped APIs to shipped after running the promotion script."
104+
105+
- name: Dispatch other workflows
106+
shell: pwsh
107+
env:
108+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
109+
run: |
110+
$owner = "${{ github.repository_owner }}"
111+
$repo = "${{ github.event.repository.name }}"
112+
$branch = "${{ github.ref_name }}"
113+
114+
# Get all workflows
115+
$workflows = gh workflow list --repo "$owner/$repo" --json name --jq '.[].name'
116+
117+
foreach ($workflow in $workflows) {
118+
if ($workflow -ne "Promote Shipped APIs") {
119+
Write-Host "Dispatching workflow: $workflow"
120+
gh workflow run "$workflow" --repo "$owner/$repo" --ref "$branch" 2>$null || Write-Host "Could not dispatch $workflow"
121+
}
122+
}

0 commit comments

Comments
 (0)