Skip to content

PP-12385: Add github action to comment on the PR with diffs of YML #10

PP-12385: Add github action to comment on the PR with diffs of YML

PP-12385: Add github action to comment on the PR with diffs of YML #10

name: Pkl to YAML Pipeline Changes
on:
pull_request:
paths:
- ci/pkl-pipelines/**
- .github/workflows/pkl-pipeline-changes.yml
permissions:
contents: read
jobs:
yaml-changes:
name: Generate YAML diffs
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
fetch-depth: '0'
path: 'pr/'
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
fetch-depth: '0'
path: 'master/'
# ref: $GITHUB_BASE_REF
ref: "pp-12343/example-pkl-pipeline-usage"
- name: Load pkl version
id: load-pkl-version
run: |
PKL_VERSION=$(cat pr/ci/pkl-pipelines/.pkl-version)
echo "PKL_VERSION=${PKL_VERSION}" | tee -a "$GITHUB_OUTPUT"
- name: Install pkl
env:
PKL_VERSION: "${{ steps.load-pkl-version.outputs.PKL_VERSION }}"
run: |
curl -L -o pkl https://github.com/apple/pkl/releases/download/${PKL_VERSION}/pkl-linux-amd64
chmod u+x pkl
mv pkl /usr/local/bin/pkl
pkl --version
- name: Generate YAML from Pkl in PR
working-directory: "pr/ci/pkl-pipelines"
run: |
echo "PWD: "
pwd
for PKL_FILE in *.pkl; do
YAML_FILE=$(sed -E 's/\.pkl$/.yml/' <<<"$PKL_FILE")
pkl eval "$PKL_FILE" > "$YAML_FILE"
done
- name: Generate YAML from Pkl in master
working-directory: "master/ci/pkl-pipelines"
run: |
for PKL_FILE in *.pkl; do
YAML_FILE=$(sed -E 's/\.pkl$/.yml/' <<<"$PKL_FILE")
pkl eval "$PKL_FILE" > "$YAML_FILE"
done
- name: Generate diffs
run: |
mkdir diffs
while read -r PIPELINE_YAML; do
if diff -uN "master/ci/pkl-pipelines/$PIPELINE_YAML" "pr/ci/pkl-pipelines/$PIPELINE_YAML" >>/dev/null 2>&1; then
echo "No diff in $PIPELINE_YAML"
else
echo "Diff in $PIPELINE_YAML"
set +e
diff -uN "master/ci/pkl-pipelines/$PIPELINE_YAML" "pr/ci/pkl-pipelines/$PIPELINE_YAML" > "diffs/$PIPELINE_YAML"
set -e
fi
done < <(find {master,pr}/ci/pkl-pipelines -name '*.yml' | sed -E 's/.*\///' | sort | uniq)
- name: Commenting on PR
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
script: |
const fs = require('fs')
const diffs = fs.readdirSync('diffs/').sort()
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
diffs.forEach((diffFile) => {
const diff = fs.readFileSync(`diffs/${diffFile}`, 'utf8')
const commentBody = `YAML diff vs master for \`${diffFile}\`:
\`\`\`diff
${diff}
\`\`\`
`
console.log(`Adding comment to PR for ${diffFile}`)
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
body: commentBody
})
console.log("Sleeping for 1 second to avoid getting rate limited")
await sleep(1000);
})