Skip to content

Add release template propagation workflow #4

Add release template propagation workflow

Add release template propagation workflow #4

Workflow file for this run

---
name: Propagate release templates
on:
pull_request:
branches:
- main
paths:
- .github/ISSUE_TEMPLATE/release.yml
# TODO also for cran-release.yml?
- .github/ISSUE_TEMPLATE/cran-release.yml
workflow_dispatch:
jobs:
propagation:
if: github.event.pull_request.draft == false
name: Propagate release templates
runs-on: ubuntu-latest
env:
PR_BRANCH_NAME: automated-release-template-propagation
strategy:
matrix:
# Run all steps in this job for the following repositories.
repos:
- name: junit-xml-diff
target-branch: main
files-to-propagate: '.github/ISSUE_TEMPLATE/release.yml .github/ISSUE_TEMPLATE/cran-release.yml'
reviewers: |-
walkowif
# TODO add remaining repositories
# TODO will there be any case in which we'd like some team as a reviewer?
# - name: <name>
# target-branch: main
# reviewers: |-
# walkowif
steps:
- name: Checkout this repo
uses: actions/checkout@v3
- name: Checkout ${{ matrix.repos.name }}
uses: actions/checkout@v3
with:
repository: ${{ github.repository_owner }}/${{ matrix.repos.name }}
path: ./extension-repo
token: ${{ secrets.REPO_GITHUB_TOKEN }}
- name: Update release template in ${{ matrix.repos.name }}
run: |
cd extension-repo && git status
# We want to branch off PR_BRANCH_NAME from the target branch
# so we switch to target branch first.
git fetch origin ${{ matrix.repos.target-branch }}
git checkout ${{ matrix.repos.target-branch }}
# Update local branch if remote branch already exists.
git fetch origin $PR_BRANCH_NAME@${{ matrix.repos.target-branch }} || true
# Switch to the branch or create if it doesn't exist.
git checkout $PR_BRANCH_NAME@${{ matrix.repos.target-branch }} || git checkout -b $PR_BRANCH_NAME@${{ matrix.repos.target-branch }}
# Pull the branch because stefanzweifel/git-auto-commit-action
# doesn't have support for automatic pulling.
git pull origin $PR_BRANCH_NAME@${{ matrix.repos.target-branch }} || true
# Copy release template from central repo.
mkdir -p .github/ISSUE_TEMPLATE
# TODO also cran-release.yml?
cp -a ../.github/ISSUE_TEMPLATE/* .github/ISSUE_TEMPLATE
- name: Commit and push changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Propagate release template from ${{ github.repository }}
file_pattern: ${{ matrix.repos.name.files-to-propagate }}
repository: extension-repo
commit_user_name: github-actions
commit_user_email: 41898282+github-actions[bot]@users.noreply.github.com
branch: ${{ env.PR_BRANCH_NAME }}@${{ matrix.repos.target-branch }}
create_branch: true
- name: Create Pull Request in ${{ matrix.repos.name }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.REPO_GITHUB_TOKEN }}
script: |
// Look for any open PRs.
const repo_owner = "${{ github.repository_owner }}";
const repo_name = "${{ matrix.repos.name }}";
const result = await github.rest.pulls.list({
owner: repo_owner,
repo: repo_name,
state: "open"
})
let create_new_pr = true;
for (const pr of result.data) {
// Look for distinct PR branch name.
if (pr.head.ref === "${{ env.PR_BRANCH_NAME }}@${{ matrix.repos.target-branch }}") {
console.log("PR with head ref " + pr.head.ref + " already exists");
create_new_pr = false;
break;
}
}
// If no PR with distinguished branch name has been found
// create a new PR to track changes to release template.
if (create_new_pr) {
console.log("Creating a new PR");
const result2 = await github.rest.pulls.create({
title: 'Propagate release template from ${{ github.repository }}',
owner: repo_owner,
repo: repo_name,
head: '${{ env.PR_BRANCH_NAME }}@${{ matrix.repos.target-branch }}',
base: '${{ matrix.repos.target-branch }}',
body: [
'This PR has been automatically generated by the ',
'release template propagation workflow from ${{ github.repository }}.',
'\n\nPlease review the changes.'
].join('')
});
// Assign reviewers to the PR.
const reviewer_list = `${{ matrix.repos.reviewers }}`.split("\n");
console.log(reviewer_list);
const result3 = await github.rest.pulls.requestReviewers({
owner: repo_owner,
repo: repo_name,
pull_number: result2.data.number,
reviewers: reviewer_list
});
}