Update GH workflows, ecosystem providers #136
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is the version of update-workflows-bridged-providers.yml scoped down to Ecosystem team owned providers. | |
# | |
# Generates a PR for the files in provider-ci/providers/* to each corresponding Pulumi provider. | |
# | |
# Note that this workflow does not generate any files - workflows must already be generated and committed to this repo | |
# when this workflow is run. | |
name: Update GH workflows, ecosystem providers | |
on: | |
schedule: | |
# 5 AM UTC ~ 10 PM PDT - specifically selected to avoid putting load on the CI system during working hours. | |
- cron: 0 5 * * * | |
workflow_dispatch: | |
inputs: | |
automerge: | |
description: Mark created PRs for auto-merging? | |
required: true | |
type: boolean | |
default: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.PULUMI_BOT_TOKEN }} | |
jobs: | |
generate-providers-list: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- id: get-providers | |
run: echo "::set-output name=providers::$(python generate_providers_list.py --team ecosystem)'" | |
working-directory: scripts | |
outputs: | |
providers: ${{ steps.get-providers.outputs.providers }} | |
deploy: | |
needs: generate-providers-list | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
# GitHub recommends only issuing 1 API request per second, and never | |
# concurrently. For more information, see: | |
# https://docs.github.com/en/rest/guides/best-practices-for-integrators#dealing-with-secondary-rate-limits | |
max-parallel: 1 | |
matrix: | |
provider: ${{ fromJson(needs.generate-providers-list.outputs.providers ) }} | |
steps: | |
- name: Clone ci-mgmt | |
uses: actions/checkout@v2 | |
with: | |
path: ci-mgmt | |
- name: Clone pulumi-${{ matrix.provider }} | |
uses: actions/checkout@v2 | |
with: | |
repository: pulumi/pulumi-${{ matrix.provider }} | |
path: pulumi-${{ matrix.provider }} | |
- name: Initialize submodule in pulumi-${{ matrix.provider }} | |
run: cd pulumi-${{ matrix.provider }} && make upstream && cd .. | |
- name: Delete existing workflows | |
run: rm pulumi-${{ matrix.provider }}/.github/workflows/*.yml | |
- name: Copy files from ci-mgmt to pulumi-${{ matrix.provider }} | |
run: | | |
cp -r ci-mgmt/provider-ci/providers/${{ matrix.provider }}/repo/. pulumi-${{ matrix.provider }}/. | |
- name: Install Go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: stable | |
- name: Run source code migrations | |
run: | | |
DIR="$PWD/pulumi-${{ matrix.provider }}" | |
cd ci-mgmt/tools/sourcemigrator | |
npm ci | |
npx ts-node index.ts "$DIR" | |
- name: Close obsolete PRs started by this workflow | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.PULUMI_BOT_TOKEN }} | |
script: | | |
const regex = /Update GitHub Actions workflows/i; | |
const octokit = github.rest; | |
const repo = 'pulumi-${{ matrix.provider }}' | |
console.log('Checking ' + repo); | |
const { data: pullRequests } = await octokit.pulls.list({ | |
owner: 'pulumi', | |
repo: repo, | |
state: 'open', | |
}); | |
for (const pullRequest of pullRequests) { | |
if (regex.test(pullRequest.title)) { | |
console.log('Closing obsolete PR ' + pullRequest.number); | |
await octokit.pulls.update({ | |
owner: 'pulumi', | |
repo: repo, | |
pull_number: pullRequest.number, | |
state: 'closed', | |
}); | |
} | |
} | |
- name: Create PR | |
id: create-pr | |
uses: peter-evans/create-pull-request@v3 | |
with: | |
author: Pulumi Bot <bot@pulumi.com> | |
body: "This PR was automatically generated by the update-workflows-ecosysetem-providers.yml workflow in the pulumi/ci-mgmt repo, from ${{ github.sha }}." | |
branch: "update-github-actions-workflows-${{ github.run_number }}" | |
committer: Pulumi Bot <bot@pulumi.com> | |
commit-message: "[internal] Update GitHub Actions workflow files" | |
labels: "impact/no-changelog-required" | |
title: "Update GitHub Actions workflows." | |
path: pulumi-${{ matrix.provider }} | |
token: ${{ secrets.PULUMI_BOT_TOKEN }} | |
- name: Set PR to auto-merge | |
if: steps.create-pr.outputs.pull-request-operation == 'created' && (github.event.inputs.automerge == 'true' || github.event_name == 'schedule') | |
run: "gh pr merge --auto --squash ${{ steps.create-pr.outputs.pull-request-url }}" | |
# See: https://docs.github.com/en/rest/guides/best-practices-for-integrators#dealing-with-secondary-rate-limits | |
- name: Sleep to prevent hitting secondary rate limits | |
run: sleep 1 |