forked from ampproject/amphtml
-
Notifications
You must be signed in to change notification settings - Fork 0
115 lines (95 loc) · 3.55 KB
/
sweep-experiments.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Executes `amp sweep-experiments` on a schedule.
# If experiments are swept, a PR is created.
name: Sweep Experiments
on:
schedule:
# First day of the month at 00:00:00
- cron: '0 0 1 * *'
permissions:
contents: read
jobs:
sweep-experiments:
permissions:
contents: write # for peter-evans/create-pull-request to create branch
issues: write # for peter-evans/create-or-update-comment to create or update comment
pull-requests: write # for peter-evans/create-pull-request to create a PR
if: github.repository == 'ampproject/amphtml'
name: Sweep Experiments
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set Up Node
uses: actions/setup-node@v2
with:
node-version: 16
- name: Set Up Environment
run: sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
- name: Install Dependencies
run: npm ci
- name: Sweep
id: sweep
run: |
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
amp sweep-experiments
title=$(git log -1 --format=%s)
title="${title//'%'/'%25'}"
title="${title//$'\n'/'%0A'}"
title="${title//$'\r'/'%0D'}"
echo "::set-output name=title::$(echo "$title")"
body=$(git log -1 --format=%b)
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo "::set-output name=body::$(echo "$body")"
hash=$(git log -1 --format=%h)
hash="${hash//'%'/'%25'}"
hash="${hash//$'\n'/'%0A'}"
hash="${hash//$'\r'/'%0D'}"
echo "::set-output name=branch::$(echo "sweep-experiments-${hash}")"
- name: Create Pull Request
id: pull-request
uses: peter-evans/create-pull-request@v3
with:
draft: true
title: ${{ steps.sweep.outputs.title }}
body: ${{ steps.sweep.outputs.body }}
branch: ${{ steps.sweep.outputs.branch }}
- name: Comment on Pull Request
if: ${{ steps.pull-request.outputs.pull-request-number }}
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ steps.pull-request.outputs.pull-request-number }}
body: |
You may checkout this pull request to follow-up manually:
```
git checkout -t upstream/${{ steps.sweep.outputs.branch }}
```
If you're a repository collaborator, you may push to the branch associated with this pull request.
- name: Cleanup Branches
if: ${{ steps.pull-request.outputs.pull-request-number }}
run: |
node build-system/tasks/sweep-experiments/cleanup-branches.js --except="${{ steps.sweep.outputs.branch }}"
create-issue-on-error:
if: failure()
needs: sweep-experiments
permissions:
contents: read
issues: write
runs-on: ubuntu-latest
environment: create_issue_on_error
steps:
- uses: actions/checkout@v3
- name: Create issue on error
uses: JasonEtco/create-an-issue@v2
with:
filename: .github/create_issue_on_error.md
env:
GITHUB_TOKEN: ${{ secrets.AMPPROJECTBOT }}
WORKFLOW_NAME: ${{ github.workflow }}
MENTION: '@ampproject/wg-infra'
REPO_SLUG: ${{ github.repository }}
RUN_ID: ${{ github.run_id }}