🚀 Update Bug Report #1136
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
name: 🚀 Update Bug Report | |
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows | |
# https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads | |
on: | |
# used for testing this action | |
# you shouldn't use this trigger in production | |
push: | |
branches: | |
- main | |
# used for testing this action | |
# you shouldn't use this trigger in production | |
pull_request: | |
branches: [main] | |
# specific to this workflow | |
create: | |
delete: | |
label: | |
types: [created, edited, deleted] | |
# use in production | |
workflow_dispatch: | |
# use in production | |
# needs ref setup | |
release: | |
branches: | |
- main | |
types: [published] | |
# use in production | |
schedule: | |
# runs daily at midnight | |
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule | |
- cron: '0 0 * * *' | |
jobs: | |
pre: | |
name: Prepare context for other jobs | |
runs-on: ubuntu-latest | |
outputs: | |
# needed in order to reference the local action | |
branch: ${{ env.job_ref }} | |
branches: ${{ steps.branches.outputs.result }} | |
labels: ${{ steps.labels.outputs.result }} | |
long: ${{ steps.long.outputs.result }} | |
long2: ${{ steps.long2.outputs.result }} | |
dates: ${{ steps.dates.outputs.result }} | |
year_end: ${{ steps.year_end.outputs.result }} | |
timestamp: ${{ steps.timestamp.outputs.value }} | |
steps: | |
- name: Setting branch for committing | |
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable | |
run: | | |
BRANCH="" | |
if [ ${{ github.event_name == 'release' }} == true ]; then | |
BRANCH=${{ github.event.release.target_commitish }} | |
elif [ ${{ github.event_name == 'create' }} == true ]; then | |
BRANCH=${{ github.event.repository.default_branch }} | |
elif [ ${{ github.event_name == 'pull_request' }} == true ]; then | |
BRANCH=${{ github.head_ref }} | |
else | |
BRANCH=${{ github.ref }} | |
fi | |
echo "job_ref=$BRANCH" >> $GITHUB_ENV | |
echo "Branch: $BRANCH" | |
- name: Get branches | |
id: branches | |
# https://github.com/actions/github-script | |
uses: actions/github-script@v6 | |
with: | |
result-encoding: string | |
# https://octokit.github.io/rest.js | |
# https://docs.github.com/en/rest/branches/branches#list-branches | |
script: | | |
return github | |
.rest.repos.listBranches(context.repo) | |
.then((res) => res.data.map((b) => b.name)); | |
- name: Get labels | |
id: labels | |
uses: actions/github-script@v6 | |
with: | |
result-encoding: string | |
# https://octokit.github.io/rest.js | |
# https://docs.github.com/en/rest/issues/labels#list-labels-for-a-repository | |
script: | | |
return github | |
.rest.issues.listLabelsForRepo(context.repo) | |
.then((res) => res.data.map((l) => l.name)); | |
- name: Generate a long array | |
id: long | |
uses: actions/github-script@v6 | |
with: | |
result-encoding: string | |
script: | | |
return new Array(500).fill(0).map((_, i) => `#${i + 1}`); | |
- name: Generate another long array | |
id: long2 | |
uses: actions/github-script@v6 | |
with: | |
result-encoding: string | |
script: | | |
return new Array(500).fill(0).map((_, i) => `#${i + 1}`).reverse(); | |
- name: Get next week | |
id: dates | |
uses: actions/github-script@v6 | |
with: | |
# unfortunately I didn't manage to import moment | |
# https://github.com/actions/github-script/issues/275 | |
script: | | |
const dayMs = 24 * 60 * 60 * 1000; | |
function format(dayDiff) { | |
const date = new Date(Date.now() + dayDiff * dayMs); | |
return `${date.getFullYear()}-${date.getMonth() + 1}-${ | |
date.getDate() < 10 ? `0${date.getDate()}` : date.getDate() | |
}`; | |
} | |
return new Array(7).fill(0).map((_, i) => format(i + 7)); | |
- name: Get dates until end of year | |
id: year_end | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const dayMs = 24 * 60 * 60 * 1000; | |
function format(dayDiff) { | |
const date = new Date(Date.now() + dayDiff * dayMs); | |
return `${date.getFullYear()}-${date.getMonth() + 1}-${ | |
date.getDate() < 10 ? `0${date.getDate()}` : date.getDate() | |
}`; | |
} | |
const jan1 = new Date(new Date().getFullYear() + 1, 0, 1) | |
return new Array(Math.floor((jan1 - new Date()) / dayMs)).fill(0).map((_, i) => format(i + 1)); | |
- name: Timestamp | |
id: timestamp | |
run: echo "::set-output name=value::$(date +'%Y-%m-%d %H:%M:%S') " | |
update-bug-report: | |
name: Update bug report on branch `${{ needs.pre.outputs.branch }}` | |
runs-on: ubuntu-latest | |
needs: pre | |
if: contains(github.actor, 'github-actions') == false | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: ${{ needs.pre.outputs.branch }} | |
- name: Update branches | |
id: branches | |
uses: ./ | |
with: | |
form: .github/ISSUE_TEMPLATE/bug_report.yml | |
dropdown: _branches | |
options: ${{ needs.pre.outputs.branches }} | |
dry_run: no-push | |
- name: Bug report modified? ${{ steps.branches.outputs.modified }} | |
run: | | |
- name: Update labels | |
id: labels | |
uses: ./ | |
with: | |
form: .github/ISSUE_TEMPLATE/bug_report.yml | |
dropdown: _labels | |
options: ${{ needs.pre.outputs.labels }} | |
dry_run: no-push | |
- name: Bug report modified? ${{ steps.labels.outputs.modified }} | |
run: | | |
- name: Update dates | |
id: dates | |
uses: ./ | |
with: | |
form: .github/ISSUE_TEMPLATE/bug_report.yml | |
dropdown: _dates | |
options: ${{ needs.pre.outputs.dates }} | |
dry_run: no-push | |
- name: Pushed? ${{ steps.branches.outputs.modified || steps.labels.outputs.modified || steps.dates.outputs.modified }} | |
if: steps.branches.outputs.modified || steps.labels.outputs.modified || steps.dates.outputs.modified | |
run: git push | |
update-long-report: | |
name: Update long report on branch `${{ needs.pre.outputs.branch }}` | |
runs-on: ubuntu-latest | |
needs: pre | |
if: contains(github.actor, 'github-actions') == false | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: ${{ needs.pre.outputs.branch }} | |
- name: Update long dropdown | |
uses: ./ | |
with: | |
template: .github/template_report.yml | |
form: .github/ISSUE_TEMPLATE/long_report.yml | |
dropdown: long | |
options: ${{ needs.pre.outputs.long }} | |
commit_message: 'chore(): update long report / long dropdown' | |
- name: Update long2 dropdown | |
uses: ./ | |
with: | |
# passing template again for testing | |
template: .github/template_report.yml | |
form: .github/ISSUE_TEMPLATE/long_report.yml | |
dropdown: long2 | |
options: ${{ needs.pre.outputs.long2 }} | |
commit_message: 'chore(): update long report / long2 dropdown' | |
- name: Update year end dropdown | |
uses: ./ | |
with: | |
# passing template again for testing | |
template: .github/template_report.yml | |
form: .github/ISSUE_TEMPLATE/long_report.yml | |
dropdown: year_end | |
options: ${{ needs.pre.outputs.year_end }} | |
commit_message: 'chore(): update long report / year_end dropdown' | |
dry_run: no-push | |
- name: Dynamic Substitution | |
uses: ./ | |
with: | |
# passing template again for testing | |
template: .github/template_report.yml | |
form: .github/ISSUE_TEMPLATE/long_report.yml | |
dropdown: _subs | |
options: '{{...}},${{ needs.pre.outputs.timestamp }}' | |
description: '{...}\nUpdated ${{ needs.pre.outputs.timestamp }}' | |
dry_run: no-push | |
- name: Commit & PR | |
uses: peter-evans/[email protected] | |
with: | |
commit-message: 'chore(): update long report / year_end dropdown' | |
add-paths: .github/ISSUE_TEMPLATE/long_report.yml | |
branch: ci-update-long-report | |
base: ${{ needs.pre.outputs.branch }} | |
delete-branch: true | |
labels: ci, bot | |
title: 'ci(`Automated`): Update year end dropdown' | |
body: | | |
Automated update to `.github/ISSUE_TEMPLATE/long_report.yml` | |
Last sha ${{ github.sha }} | |
Created with | |
[![create-pull-request](https://img.shields.io/github/v/release/peter-evans/create-pull-request?label=peter-evans%2Fcreate-pull-request&sort=semver)](https://github.com/marketplace/actions/create-pull-request) |