forked from DataDog/dd-trace-dotnet
68 lines (58 loc) · 2.18 KB
/
code_freeze_end.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
name: End code freeze
on:
workflow_dispatch:
milestone:
types: [closed, deleted, edited]
jobs:
end_code_freeze:
if: |
github.event_name == 'workflow_dispatch'
|| (github.event.milestone.title == 'Code Freeze' && github.event.milestone.state == 'closed')
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
steps:
- uses: octokit/request-action@v2.x
name: 'Close Code Freeze Milestone'
id: milestones
if: github.event_name == 'workflow_dispatch'
with:
route: PATCH /repos/{owner}/{repo}/milestones/115
owner: DataDog
repo: dd-trace-dotnet
state: closed
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- uses: octokit/request-action@v2.x
name: 'Get open PRs'
id: prs
with:
route: GET /repos/{owner}/{repo}/pulls
owner: DataDog
repo: dd-trace-dotnet
state: open
base: master
per_page: 100 # max value, for simplicity. If we have more than 100 pull requests open, then we need to revisit!
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- run: |
set -o pipefail
json=$(cat << 'ENDOFMESSAGE'
${{ steps.prs.outputs.data }}
ENDOFMESSAGE
)
arrayLength=$(echo $json | jq -r 'length')
echo "Updating code freeze status for $arrayLength PRs"
arrayLength=$((arrayLength-1))
for i in $(seq 0 $arrayLength); do
title=$(echo $json | jq -r ".[$i].title")
echo "Removing code freeze for '$title'"
sha=$(echo $json | jq -r ".[$i].head.sha")
targetUrl="https://github.com/DataDog/dd-trace-dotnet/actions/workflows/code_freeze_end.yml"
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/DataDog/dd-trace-dotnet/statuses/$sha" \
-d '{"state":"success","context":"code_freeze","description":"No code freeze is in place","target_url":"'"$targetUrl"'"}'
done
name: 'Update all PRs with Code Freeze status'