|
|
@@ -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
|