Parcourir la source

Move PR labelling to a separate (scheduled) workflow

See https://github.community/t5/GitHub-Actions/GitHub-actions-are-severely-limited-on-PRs/m-p/54669/highlight/true#M9249
Tianon Gravi il y a 5 ans
Parent
commit
a40bfb3617
3 fichiers modifiés avec 59 ajouts et 47 suppressions
  1. 59 0
      .github/workflows/label-prs.yml
  2. 0 22
      .github/workflows/pr-labels.sh
  3. 0 25
      .github/workflows/test-pr.yml

+ 59 - 0
.github/workflows/label-prs.yml

@@ -0,0 +1,59 @@
+# 🤬 https://github.com/actions/labeler/issues/12 / https://github.community/t5/GitHub-Actions/GitHub-actions-are-severely-limited-on-PRs/m-p/54669/highlight/true#M9249
+# (this workflow shouldn't exist)
+
+name: Label PRs
+
+on:
+  schedule:
+    - cron: '*/15 * * * *'
+
+defaults:
+  run:
+    shell: 'bash -Eeuo pipefail -x {0}'
+
+jobs:
+
+  label:
+    name: Label
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v2
+      - name: Apply Labels
+        uses: actions/[email protected]
+        with:
+          script: |
+            const { data: pulls } = await github.pulls.list({
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              state: 'open',
+              sort: 'updated',
+              direction: 'desc',
+              per_page: 100,
+            });
+            for (let i = 0; i < pulls.length; ++i) {
+              let pull = pulls[i];
+              const { data: files } = await github.pulls.listFiles({
+                owner: context.repo.owner,
+                repo: context.repo.repo,
+                pull_number: pull.number,
+              });
+              const currentLabels = pull.labels.map((label) => { return label.name });
+              const newLabels = files.map((file) => {
+                if (file.filename.startsWith('library/')) {
+                  if (file.status === 'added') {
+                    return [ file.filename, 'new-image' ];
+                  } else {
+                    return [ file.filename ];
+                  }
+                }
+                return [];
+              }).flat().filter((label) => { return !currentLabels.includes(label) });
+              if (newLabels.length > 0) {
+                await github.issues.addLabels({
+                  owner: context.repo.owner,
+                  repo: context.repo.repo,
+                  issue_number: pull.number,
+                  labels: newLabels,
+                });
+              }
+            }

+ 0 - 22
.github/workflows/pr-labels.sh

@@ -1,22 +0,0 @@
-#!/usr/bin/env bash
-set -Eeuo pipefail
-
-git fetch --quiet https://github.com/docker-library/official-images.git master
-
-changes="$(git diff --numstat FETCH_HEAD...HEAD -- library/ | cut -d$'\t' -f3-)"
-set -- $changes
-
-if [ "$#" -eq 0 ]; then
-	echo >&2 'No library/ changes detected, skipping labels.'
-	exit
-fi
-
-if newImages="$(git diff --name-only --diff-filter=A FETCH_HEAD...HEAD -- "$@")" && [ -n "$newImages" ]; then
-	echo >&2
-	echo >&2 "NEW IMAGES: $newImages"
-	echo >&2
-	set -- "$@" 'new-image'
-fi
-
-IFS=$'\n'
-echo "$*"

+ 0 - 25
.github/workflows/test-pr.yml

@@ -22,31 +22,6 @@ jobs:
           bashbrew --version
           .github/workflows/naughty.sh
 
-  label:
-    name: Label
-    runs-on: ubuntu-latest
-    steps:
-      - uses: actions/checkout@v2
-      - id: labels
-        name: Generate List
-        run: |
-          labels="$(.github/workflows/pr-labels.sh)"
-          labels="$(jq -Rsc 'rtrimstr("\n") | split("\n") | { labels: ., count: length }' <<<"$labels")"
-          jq . <<<"$labels"
-          echo "::set-output name=labels::$labels"
-      - name: Apply Labels
-        uses: actions/[email protected]
-        with:
-          script: |
-            const data = ${{ steps.labels.outputs.labels }}
-            github.issues.addLabels({
-              owner: context.repo.owner,
-              repo: context.repo.repo,
-              issue_number: context.payload.pull_request.number,
-              labels: data.labels,
-            })
-        if: fromJSON(steps.labels.outputs.labels).count > 0
-
   diff:
     name: Diff
     runs-on: ubuntu-latest