forked from DataDog/dd-trace-dotnet
73 lines (65 loc) · 2.52 KB
/
code_freeze_start.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
69
70
71
72
73
name: Start code freeze
on:
workflow_dispatch:
milestone:
types: [opened, created, edited]
jobs:
start_code_freeze:
if: |
github.event_name == 'workflow_dispatch' ||
(github.event.milestone.title == 'Code Freeze' && github.event.milestone.state == 'open')
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
steps:
- uses: octokit/request-action@v2.x
name: 'Open 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: open
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 "Setting code freeze for '$title'"
sha=$(echo $json | jq -r ".[$i].head.sha")
targetUrl="https://github.com/DataDog/dd-trace-dotnet/actions/workflows/code_freeze_start.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":"failure","context":"code_freeze","description":"A code freeze is in place","target_url":"'"$targetUrl"'"}'
done
name: 'Update all PRs with Code Freeze status'
- name: Trigger AAS deploy
run: |
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${{ secrets.GH_TOKEN_PIERO }}" \
https://api.github.com/repos/DataDog/datadog-aas-extension/dispatches \
-d '{"event_type": "dd-trace-code-freeze", "client_payload": {"sha":"'"$GITHUB_SHA"'" } }'