Skip to content

[Problem] cluster grace period can't be set to unlimited #923

[Problem] cluster grace period can't be set to unlimited

[Problem] cluster grace period can't be set to unlimited #923

name: Backports
# This workflow generates "backport" issues when a release branch label is added to an issue
on:
issues:
types: [labeled] # triggered when any label is added to an issue
env :
TERRAFORM_MAINTAINERS: ${{ vars.TERRAFORM_MAINTAINERS }} # eg. ["matttrach"]
permissions: {}
jobs:
create-issue:
name: 'Create Backport Issue'
runs-on: ubuntu-latest
if: startsWith(github.event.label.name, 'release/v')
timeout-minutes: 10
permissions:
issues: write
contents: read
steps:
- name: Find and Verify PR Number
id: extract-pr
# https://github.com/actions/github-script/releases
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const body = context.payload.issue.body;
if (!body) {
core.setFailed('Issue body is empty.');
return;
}
const regex = /#(\d+)/g;
const matches = body.matchAll(regex);
const potentialNumbers = Array.from(matches, m => m[1]);
for (const number of potentialNumbers) {
try {
const { data: issue } = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: number,
});
if (issue.pull_request) {
return number;
}
} catch (error) {
// Ignore errors, likely due to some other tag in the issue body.
core.info(`Could not retrieve issue #${number}: ${error.message}`);
}
}
core.setFailed('No valid PR found.');
- name: Create GitHub Issue
id: create-github-issue
# https://github.com/actions/github-script/releases
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env :
TERRAFORM_MAINTAINERS: ${{env.TERRAFORM_MAINTAINERS}}
PR: ${{ steps.extract-pr.outputs.result }}
SCRIPT_MODE: backport-issues
with:
script: |
// Checking out the repository is a security risk, so we instead fetch the script content directly
// This allows us to validate the script in code reviews before merging
const response = await github.rest.repos.getContent({
owner: context.repo.owner,
repo: context.repo.repo,
path: ".github/workflows/scripts/backports.js",
// 'context.sha' is the SHA of the last commit on the default branch for this trigger
ref: context.sha,
});
const scriptContent = Buffer.from(response.data.content, "base64").toString();
// Write the script to a temporary file and require it to avoid eval()
const fs = require('fs');
const path = require('path');
const { pathToFileURL } = require('url');
const tempPath = path.join(process.env.RUNNER_TEMP, 'backports.mjs');
fs.writeFileSync(tempPath, scriptContent, 'utf8');
const { default: script } = await import(pathToFileURL(tempPath).href);
await script({github, context, core, process});