Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fef70b0
docs(core): match code snippet name with filename (#1286)
heitorlessa Jul 8, 2022
d918387
fix(ci): accept core arg in label related issue workflow
heitorlessa Jul 8, 2022
92b475b
docs(graphql): snippets split, improved, and lint (#1287)
heitorlessa Jul 11, 2022
2d4df8a
chore(ci): convert inline gh-script to file
heitorlessa Jul 11, 2022
a81a2d0
chore(ci): make export PR reusable
heitorlessa Jul 11, 2022
7925949
chore(ci): on_merge workflow to workflow_run due to permissions issue
heitorlessa Jul 11, 2022
814b0ee
fix(ci): correct new job conditionals
heitorlessa Jul 11, 2022
58fd00d
fix(ci): ensure reusable workflows checkout code regardless
heitorlessa Jul 11, 2022
753e648
fix(ci): on_merge job conditional dependabot
heitorlessa Jul 11, 2022
710501d
fix(ci): use env var since nested reusable workflows dont share inputs
heitorlessa Jul 11, 2022
a5b70b6
fix(ci): use relative path to save artifact
heitorlessa Jul 11, 2022
472a050
chore(ci): convert inline gh-script to file to ease debugging
heitorlessa Jul 11, 2022
69c82d3
fix(ci): ensure checkout is run on other jobs; label_pr
heitorlessa Jul 11, 2022
a66e377
chore(ci): debug unresolved env vars
heitorlessa Jul 11, 2022
3bb8356
chore(ci): debug job outputs
heitorlessa Jul 11, 2022
7333a15
chore(ci): debug job outputs 2
heitorlessa Jul 11, 2022
9bd5181
chore(ci): debug job outputs 3
heitorlessa Jul 11, 2022
e2c7802
chore(ci): debug job outputs 4
heitorlessa Jul 11, 2022
58ad8df
chore(ci): debug job outputs 5
heitorlessa Jul 11, 2022
3a90d21
chore(ci): debug job outputs 6
heitorlessa Jul 11, 2022
d7612c1
chore(ci): debug job outputs 7
heitorlessa Jul 11, 2022
03a0ea9
chore(ci): debug job outputs 8
heitorlessa Jul 11, 2022
64b0264
chore(ci): debug job outputs 9
heitorlessa Jul 11, 2022
60e1836
chore(ci): debug job outputs 10
heitorlessa Jul 11, 2022
d2b81b8
chore(ci): actual fix for output mapping
heitorlessa Jul 11, 2022
65e875b
chore(ci): try new workflow
heitorlessa Jul 11, 2022
923becf
chore(ci): never gonna give you up
heitorlessa Jul 11, 2022
74356dc
fix(ci): label pr based on title workflow
heitorlessa Jul 11, 2022
d4d3dec
chore(deps-dev): bump flake8-black from 0.2.3 to 0.2.4
dependabot[bot] Sep 5, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/scripts/download_pr_artifact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = async ({github, context, core}) => {
const fs = require('fs');

const workflowRunId = process.env.WORKFLOW_ID;
core.info(`Listing artifacts for workflow run ${workflowRunId}`);

const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: workflowRunId,
});

const matchArtifact = artifacts.data.artifacts.filter(artifact => artifact.name == "pr")[0];

core.info(`Downloading artifacts for workflow run ${workflowRunId}`);
const artifact = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});

core.info("Saving artifact found", artifact);

fs.writeFileSync('pr.zip', Buffer.from(artifact.data));
}
39 changes: 39 additions & 0 deletions .github/scripts/label_pr_based_on_title.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module.exports = async ({github, context, core}) => {
const pr_number = process.env.PR_NUMBER
const pr_title = process.env.PR_TITLE

console.log(pr_title)

const FEAT_REGEX = /feat(\((.+)\))?(\:.+)/
const BUG_REGEX = /(fix|bug)(\((.+)\))?(\:.+)/
const DOCS_REGEX = /(docs|doc)(\((.+)\))?(\:.+)/
const CHORE_REGEX = /(chore)(\((.+)\))?(\:.+)/
const DEPRECATED_REGEX = /(deprecated)(\((.+)\))?(\:.+)/
const REFACTOR_REGEX = /(refactor)(\((.+)\))?(\:.+)/

const labels = {
"feature": FEAT_REGEX,
"bug": BUG_REGEX,
"documentation": DOCS_REGEX,
"internal": CHORE_REGEX,
"enhancement": REFACTOR_REGEX,
"deprecated": DEPRECATED_REGEX,
}

for (const label in labels) {
const matcher = new RegExp(labels[label])
const isMatch = matcher.exec(pr_title)
if (isMatch != null) {
console.info(`Auto-labeling PR ${pr_number} with ${label}`)

await github.rest.issues.addLabels({
issue_number: pr_number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: [label]
})

break
}
}
}
10 changes: 6 additions & 4 deletions .github/scripts/label_related_issue.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
module.exports = async ({github, context}) => {
const prBody = context.payload.body;
const prNumber = context.payload.number;
module.exports = async ({github, context, core}) => {
const prBody = process.env.PR_BODY;
const prNumber = process.env.PR_NUMBER;
const releaseLabel = process.env.RELEASE_LABEL;
const maintainersTeam = process.env.MAINTAINERS_TEAM
const maintainersTeam = process.env.MAINTAINERS_TEAM;

console.log(prBody);

const RELATED_ISSUE_REGEX = /Issue number:[^\d\r\n]+(?<issue>\d+)/;

Expand Down
15 changes: 15 additions & 0 deletions .github/scripts/save_pr_details.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = async ({github, context, core}) => {
const fs = require('fs');
const filename = "pr.txt";

try {
core.debug("Payload as it comes..");
core.debug(context.payload);
fs.writeFileSync(`./${filename}`, JSON.stringify(context.payload));

return `PR successfully saved ${filename}`
} catch (err) {
core.setFailed("Failed to save PR details");
console.error(err);
}
}
75 changes: 0 additions & 75 deletions .github/workflows/export_pr_details.yml

This file was deleted.

88 changes: 19 additions & 69 deletions .github/workflows/label_pr_on_title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,86 +2,36 @@ name: Label PR based on title

on:
workflow_run:
workflows: ["Record PR number"]
workflows: ["Record PR details"]
types:
- completed

jobs:
upload:
runs-on: ubuntu-latest
get_pr_details:
# Guardrails to only ever run if PR recording workflow was indeed
# run in a PR event and ran successfully
if: >
${{ github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success' }}
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: ./.github/workflows/reusable_export_pr_details.yml
with:
record_pr_workflow_id: ${{ github.event.workflow_run.id }}
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
label_pr:
needs: get_pr_details
runs-on: ubuntu-latest
steps:
- name: 'Download artifact'
uses: actions/github-script@v6
# For security, we only download artifacts tied to the successful PR recording workflow
with:
script: |
const fs = require('fs');

const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});

const matchArtifact = artifacts.data.artifacts.filter(artifact => artifact.name == "pr")[0];

const artifact = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});

fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(artifact.data));
# NodeJS standard library doesn't provide ZIP capabilities; use system `unzip` command instead
- run: unzip pr.zip

- name: 'Label PR based on title'
- name: Checkout repository
uses: actions/checkout@v3
- name: "Label PR based on title"
uses: actions/github-script@v6
env:
PR_NUMBER: ${{ needs.get_pr_details.outputs.prNumber }}
PR_TITLE: ${{ needs.get_pr_details.outputs.prTitle }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# This safely runs in our base repo, not on fork
# thus allowing us to provide a write access token to label based on PR title
# and label PR based on semantic title accordingly
script: |
const fs = require('fs');
const pr_number = Number(fs.readFileSync('./number'));
const pr_title = fs.readFileSync('./title', 'utf-8').trim();

const FEAT_REGEX = /feat(\((.+)\))?(\:.+)/
const BUG_REGEX = /(fix|bug)(\((.+)\))?(\:.+)/
const DOCS_REGEX = /(docs|doc)(\((.+)\))?(\:.+)/
const CHORE_REGEX = /(chore)(\((.+)\))?(\:.+)/
const DEPRECATED_REGEX = /(deprecated)(\((.+)\))?(\:.+)/
const REFACTOR_REGEX = /(refactor)(\((.+)\))?(\:.+)/

const labels = {
"feature": FEAT_REGEX,
"bug": BUG_REGEX,
"documentation": DOCS_REGEX,
"internal": CHORE_REGEX,
"enhancement": REFACTOR_REGEX,
"deprecated": DEPRECATED_REGEX,
}

for (const label in labels) {
const matcher = new RegExp(labels[label])
const isMatch = matcher.exec(pr_title)
if (isMatch != null) {
console.info(`Auto-labeling PR ${pr_number} with ${label}`)

await github.rest.issues.addLabels({
issue_number: pr_number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: [label]
})

break
}
}
const script = require('.github/scripts/label_pr_based_on_title.js')
await script({github, context, core})
37 changes: 29 additions & 8 deletions .github/workflows/on_merged_pr.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,47 @@
# Maintenance: Verify why we're having permissions issues even with write scope, then re-enable it.
# logs: https://github.com/awslabs/aws-lambda-powertools-python/runs/7030238348?check_suite_focus=true
name: On PR merge

on:
pull_request:
workflow_run:
workflows: ["Record PR details"]
types:
- closed
- completed

env:
RELEASE_LABEL: "pending-release"
MAINTAINERS_TEAM: "@awslabs/aws-lambda-powertools-python"

jobs:
get_pr_details:
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
uses: ./.github/workflows/reusable_export_pr_details.yml
with:
record_pr_workflow_id: ${{ github.event.workflow_run.id }}
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
release_label_on_merge:
if: github.event.pull_request.merged == true && github.event.pull_request.user.login != 'dependabot[bot]'
needs: get_pr_details
if: >
${{ needs.get_pr_details.outputs.prAuthor != 'dependabot[bot]' &&
needs.get_pr_details.outputs.prAction == 'opened'
}}
# if: >
# ${{ needs.get_pr_details.outputs.prAuthor != 'dependabot[bot]' &&
# needs.get_pr_details.outputs.prAction == 'opened' &&
# needs.get_pr_details.outputs.prIsMerged == true
# }}
# if: ${{ needs.get_pr_details.outputs.prIsMerged == true }}
runs-on: ubuntu-latest
permissions:
issues: write # required for new scoped token
pull-requests: write # required for new scoped token
steps:
- uses: actions/checkout@v3
- name: "Label PR related issue for release"
uses: actions/github-script@v6
env:
PR_NUMBER: ${{ needs.get_pr_details.outputs.prNumber }}
PR_TITLE: ${{ needs.get_pr_details.outputs.prTitle }}
PR_BODY: ${{ needs.get_pr_details.outputs.prBody }}
PR_AUTHOR: ${{ needs.get_pr_details.outputs.prAuthor }}
PR_ACTION: ${{ needs.get_pr_details.outputs.prAction }}
PR_MERGE: ${{ needs.get_pr_details.outputs.prIsMerged }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/on_opened_pr.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
name: On PR opened

on:
workflow_run:
workflows: ["Record PR number"]
workflows: ["Record PR details"]
types:
- completed

env:
BLOCK_LABEL: "do-not-merge"
BLOCK_REASON_LABEL: "need-issue"

# TODO: include markdownify author too
jobs:
get_pr_details:
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
uses: ./.github/workflows/export_pr_details.yml
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: ./.github/workflows/reusable_export_pr_details.yml
with:
record_pr_workflow_id: ${{ github.event.workflow_run.id }}
secrets:
Expand Down
22 changes: 10 additions & 12 deletions .github/workflows/record_pr.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
name: Record PR number
name: Record PR details

on:
pull_request:
types: [opened, edited]
types: [opened, edited, closed]

jobs:
build:
record_pr:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Save PR number
run: |
mkdir -p ./pr
echo ${{ github.event.number }} > ./pr/number
echo "${{ github.event.pull_request.title }}" > ./pr/title
echo "${{ github.event.pull_request.body }}" > ./pr/body
echo "${{ github.event.pull_request.user.login }}" > ./pr/author
echo "${{ github.event.action }}" > ./pr/action
- name: "Extract PR details"
uses: actions/github-script@v6
with:
script: |
const script = require('.github/scripts/save_pr_details.js')
await script({github, context, core})
- uses: actions/upload-artifact@v3
with:
name: pr
path: pr/
path: pr.txt
Loading