Skip to content

Sweep Experiments

Sweep Experiments #12

# 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: Harden Runner
uses: step-security/harden-runner@55d479fb1c5bcad5a4f9099a5d9f37c8857b2845 # v2.4.1
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
- name: Checkout Repo
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
fetch-depth: 0
- name: Set Up Node
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3.7.0
with:
node-version: lts/*
- 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 "title=$(echo "$title")" >> $GITHUB_OUTPUT
body=$(git log -1 --format=%b)
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo "body=$(echo "$body")" >> $GITHUB_OUTPUT
hash=$(git log -1 --format=%h)
hash="${hash//'%'/'%25'}"
hash="${hash//$'\n'/'%0A'}"
hash="${hash//$'\r'/'%0D'}"
echo "branch=$(echo "sweep-experiments-${hash}")" >> $GITHUB_OUTPUT
- name: Create Pull Request
id: pull-request
uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38 # v5.0.2
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@c6c9a1a66007646a28c153e2a8580a5bad27bcfa # v3.0.2
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:
- name: Harden Runner
uses: step-security/harden-runner@55d479fb1c5bcad5a4f9099a5d9f37c8857b2845 # v2.4.1
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: Create issue on error
uses: JasonEtco/create-an-issue@e27dddc79c92bc6e4562f268fffa5ed752639abd # v2.9.1
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 }}