Make "Munge PR" more intelligent
This commit is contained in:
parent
5e4434a291
commit
f0edc7c298
7
.github/workflows/generate.sh
vendored
7
.github/workflows/generate.sh
vendored
|
@ -1,11 +1,16 @@
|
|||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
#
|
||||
# NOTE: this is *not* a good example for integrating these tests into your own repository!
|
||||
# If you want that, check out https://github.com/docker-library/golang/blob/3f2c52653043f067156ce4f41182c2a758c4c857/.github/workflows/ci.yml instead.
|
||||
#
|
||||
|
||||
bashbrewDir="$1"; shift
|
||||
|
||||
if [ "$#" -eq 0 ]; then
|
||||
git fetch --quiet https://github.com/docker-library/official-images.git master
|
||||
changes="$(git diff --numstat FETCH_HEAD...HEAD -- library/ | cut -d$'\t' -f3-)"
|
||||
changes="$(git diff --no-renames --name-only --diff-filter='d' FETCH_HEAD...HEAD -- library/)"
|
||||
repos="$(xargs -rn1 basename <<<"$changes")"
|
||||
set -- $repos
|
||||
fi
|
||||
|
|
82
.github/workflows/munge-pr.yml
vendored
82
.github/workflows/munge-pr.yml
vendored
|
@ -13,8 +13,8 @@ env:
|
|||
|
||||
jobs:
|
||||
|
||||
apply-labels:
|
||||
name: Apply Labels
|
||||
gather:
|
||||
name: Gather Metadata
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
@ -22,34 +22,63 @@ jobs:
|
|||
# ideally this would be "github.event.pull_request.merge_commit_sha" but according to https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls#get-a-pull-request if "mergeable" is null (meaning there's a background job in-progress to check mergeability), that value is undefined...
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
fetch-depth: 0
|
||||
- id: labels
|
||||
name: Gather List
|
||||
- id: gather
|
||||
name: Affected Images
|
||||
run: |
|
||||
git fetch --quiet https://github.com/docker-library/official-images.git master
|
||||
labels="$(git diff --numstat FETCH_HEAD...HEAD -- library/ | cut -d$'\t' -f3-)"
|
||||
if [ -n "$labels" ] && newImages="$(git diff --name-only --diff-filter=A FETCH_HEAD...HEAD -- $labels)" && [ -n "$newImages" ]; then
|
||||
labels+=$'\nnew-image'
|
||||
images="$(git diff --no-renames --name-only FETCH_HEAD...HEAD -- library/)"
|
||||
if [ -n "$images" ]; then
|
||||
new="$(git diff --no-renames --name-only --diff-filter=A FETCH_HEAD...HEAD -- $images)"
|
||||
deleted="$(git diff --no-renames --name-only --diff-filter=D FETCH_HEAD...HEAD -- $images)"
|
||||
else
|
||||
new=
|
||||
deleted=
|
||||
fi
|
||||
labels="$(jq -Rsc 'rtrimstr("\n") | split("\n") | { labels: ., count: length }' <<<"$labels")"
|
||||
jq . <<<"$labels"
|
||||
echo "::set-output name=labels::$labels"
|
||||
export images new deleted
|
||||
images="$(jq -cn '
|
||||
(env.images | rtrimstr("\n") | split("\n")) as $images
|
||||
| (env.new | rtrimstr("\n") | split("\n")) as $new
|
||||
| (env.deleted | rtrimstr("\n") | split("\n")) as $deleted
|
||||
| {
|
||||
images: $images,
|
||||
count: ($images | length),
|
||||
new: $new,
|
||||
deleted: $deleted,
|
||||
}
|
||||
')"
|
||||
jq . <<<"$images"
|
||||
echo "::set-output name=images::$images"
|
||||
outputs:
|
||||
images: '${{ steps.gather.outputs.images }}'
|
||||
|
||||
apply-labels:
|
||||
name: Apply Labels
|
||||
runs-on: ubuntu-latest
|
||||
needs: gather
|
||||
if: fromJSON(needs.gather.outputs.images).count > 0
|
||||
steps:
|
||||
- name: Apply Labels
|
||||
uses: actions/github-script@v3
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const data = ${{ steps.labels.outputs.labels }};
|
||||
const data = ${{ needs.gather.outputs.images }};
|
||||
var labels = data.images;
|
||||
if (data.new.length > 0) {
|
||||
labels.push('new-image');
|
||||
}
|
||||
github.issues.addLabels({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: context.payload.pull_request.number,
|
||||
labels: data.labels,
|
||||
labels: labels,
|
||||
});
|
||||
if: fromJSON(steps.labels.outputs.labels).count > 0
|
||||
|
||||
diff:
|
||||
name: Diff Comment
|
||||
runs-on: ubuntu-latest
|
||||
needs: gather
|
||||
if: fromJSON(needs.gather.outputs.images).count > 0
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
|
@ -62,15 +91,23 @@ jobs:
|
|||
bashbrewVersion="$(< bashbrew-version)"
|
||||
docker build --pull --tag oisupport/bashbrew:base "https://github.com/docker-library/bashbrew.git#v$bashbrewVersion"
|
||||
docker build --tag oisupport/bashbrew:diff-pr .
|
||||
- id: diff
|
||||
name: Generate Diff
|
||||
- name: Gather Maintainers
|
||||
env:
|
||||
IMAGES: ${{ needs.gather.outputs.images }}
|
||||
run: |
|
||||
files="$(jq <<<"$IMAGES" -r '.images | map(@sh) | join(" ")')"
|
||||
eval "set -- $files"
|
||||
for f; do
|
||||
if [ -s "$f" ]; then
|
||||
docker run --rm --read-only --tmpfs /tmp oisupport/bashbrew:diff-pr \
|
||||
bashbrew cat --format ' - `{{ $.RepoName }}`:{{ range .Manifest.Global.Maintainers }} @{{ .Handle }}{{ end }}' "$f"
|
||||
fi
|
||||
done | tee "$GITHUB_WORKSPACE/oi-pr.maint"
|
||||
- name: Generate Diff
|
||||
env:
|
||||
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||
run: |
|
||||
docker run --rm --read-only --tmpfs /tmp oisupport/bashbrew:diff-pr ./diff-pr.sh "$GITHUB_PR_NUMBER" | tee "$GITHUB_WORKSPACE/oi-pr.diff"
|
||||
set +x
|
||||
length="$(jq -Rcs 'length' "$GITHUB_WORKSPACE/oi-pr.diff")"
|
||||
echo "::set-output name=length::$length"
|
||||
- name: Comment
|
||||
uses: actions/github-script@v3
|
||||
with:
|
||||
|
@ -99,8 +136,12 @@ jobs:
|
|||
}
|
||||
if (needNewComment) {
|
||||
const fs = require('fs');
|
||||
const diff = fs.readFileSync(process.env.GITHUB_WORKSPACE + '/oi-pr.diff');
|
||||
const body = "<details>\n<summary>" + commentText + "</summary>\n\n```diff\n" + diff + "\n```\n\n</details>";
|
||||
const diff = fs.readFileSync(process.env.GITHUB_WORKSPACE + '/oi-pr.diff').toString().trimEnd();
|
||||
var body = "<details>\n<summary>" + commentText + "</summary>\n\n```diff\n" + diff + "\n```\n\n</details>";
|
||||
const maint = fs.readFileSync(process.env.GITHUB_WORKSPACE + '/oi-pr.maint').toString().trimEnd();
|
||||
if (maint.length > 0) {
|
||||
body += "\n\nRelevant Maintainers:\n\n" + maint;
|
||||
}
|
||||
await github.issues.createComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
|
@ -108,4 +149,3 @@ jobs:
|
|||
body: body,
|
||||
});
|
||||
}
|
||||
if: fromJSON(steps.diff.outputs.length) > 0
|
||||
|
|
2
.github/workflows/naughty.sh
vendored
2
.github/workflows/naughty.sh
vendored
|
@ -3,7 +3,7 @@ set -Eeuo pipefail
|
|||
|
||||
if [ "$#" -eq 0 ]; then
|
||||
git fetch --quiet https://github.com/docker-library/official-images.git master
|
||||
changes="$(git diff --numstat FETCH_HEAD...HEAD -- library/ | cut -d$'\t' -f3-)"
|
||||
changes="$(git diff --no-renames --name-only --diff-filter='d' FETCH_HEAD...HEAD -- library/)"
|
||||
repos="$(xargs -rn1 basename <<<"$changes")"
|
||||
set -- $repos
|
||||
fi
|
||||
|
|
6
.github/workflows/test-pr.yml
vendored
6
.github/workflows/test-pr.yml
vendored
|
@ -33,6 +33,7 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
strategy: ${{ steps.generate-jobs.outputs.strategy }}
|
||||
length: ${{ steps.generate-jobs.outputs.length }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
|
@ -44,10 +45,13 @@ jobs:
|
|||
strategy="$(.github/workflows/generate.sh ~/bashbrew)"
|
||||
jq . <<<"$strategy" # sanity check / debugging aid
|
||||
echo "::set-output name=strategy::$strategy"
|
||||
length="$(jq <<<"$strategy" -r '.matrix.include | length')"
|
||||
echo "::set-output name=length::$length"
|
||||
|
||||
test:
|
||||
needs: generate-jobs
|
||||
strategy: ${{ fromJson(needs.generate-jobs.outputs.strategy) }}
|
||||
strategy: ${{ fromJSON(needs.generate-jobs.outputs.strategy) }}
|
||||
if: needs.generate-jobs.outputs.length > 0
|
||||
name: ${{ matrix.name }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
|
|
|
@ -80,7 +80,7 @@ else
|
|||
fi
|
||||
|
||||
if [ "$#" -eq 0 ]; then
|
||||
images="$(git -C oi/library diff --name-only HEAD...pull -- .)"
|
||||
images="$(git -C oi/library diff --no-renames --name-only HEAD...pull -- .)"
|
||||
[ -n "$images" ] || exit 0
|
||||
images="$(xargs -n1 basename <<<"$images")"
|
||||
set -- $images
|
||||
|
|
Loading…
Reference in a new issue