-
Notifications
You must be signed in to change notification settings - Fork 4
94 lines (86 loc) · 3.13 KB
/
pkl-pipeline-changes.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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
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
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/pkl-pipelines/$PIPELINE_YAML" "pr/pkl-pipelines/$PIPELINE_YAML" >>/dev/null 2>&1; then
echo "No diff in $PIPELINE_YAML"
else
echo "Diff in $PIPELINE_YAML"
diff -uN "master/pkl-pipelines/$PIPELINE_YAML" "pr/pkl-pipelines/$PIPELINE_YAML" > "diffs/$PIPELINE_YAML"
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()
diffs.forEach((diffFile) => {
const diff = fs.readFileSync(`diffs/${diffFile}`, 'utf8')
const commentBody = `YAML diff vs master for \`${diffFile}\`:
\`\`\`diff
${diff}
\`\`\`
`
})
console.log("COMMENT WOULD BE:")
console.log("=======================")
console.log(commentBody)
console.log("=======================")
// github.rest.issues.createComment({
// issue_number: context.issue.number,
// owner: context.repo.owner,
// repo: context.repo.repo
// body: commentBody
// })