Skip to content

Commit

Permalink
Draft for removing labels and report
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedikt Volkel committed Mar 26, 2024
1 parent 8cc6d6d commit e4b0e50
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/async-create-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: Print labels
runs-on: ubuntu-latest
# only run if the created branch or tag starts with the correct pattern, namely "async-"
if: startsWith(github.ref, 'refs/heads/async-') || startsWith(github.ref, 'refs/tags/async-')
if: startsWith(github.ref, 'refs/heads/async-v') || startsWith(github.ref, 'refs/tags/async-v')
steps:
- name: Create async branch or tag label
env:
Expand All @@ -34,6 +34,3 @@ jobs:
# extract only the branch or tag pattern we are really interested in
ref="${ref##*/}"
gh label create --repo "${GITHUB_REPOSITORY}" "${ref}" --description "Concerns ${what_am_i} ${ref}" --color 95C6F0
# create the corresponding "<label-name>-accepted" label
ref_accepted="${ref}-accepted"
gh label create --repo "${GITHUB_REPOSITORY}" "${ref_accepted}" --description "Concerns ${what_am_i} ${ref}" --color 95C6F0
67 changes: 67 additions & 0 deletions .github/workflows/async-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
name: Update when async branch is pushed

'on':
workflow_call:

permissions:
pull-requests: write # to create labels, see https://docs.github.com/en/rest/issues/labels?apiVersion=2022-11-28#create-a-label

jobs:
update:
name: Update everything
runs-on: ubuntu-latest
# only run if the created branch or tag starts with the correct pattern, namely "async-"
if: startsWith(github.ref, 'refs/heads/async-v')
steps:
- name: Update, remove labels, publish table
env:
GH_TOKEN: ${{ github.token }}
ref: ${{ github.ref }}

id: create_label
run: |

Check failure on line 23 in .github/workflows/async-update.yml

View workflow job for this annotation

GitHub Actions / actionlint

shellcheck reported issue in this script: SC1073:error:17:1: Couldn't parse this while loop. Fix to allow more checks ``` run: | ^~~~ ```

Check failure on line 23 in .github/workflows/async-update.yml

View workflow job for this annotation

GitHub Actions / actionlint

shellcheck reported issue in this script: SC1061:error:17:22: Couldn't find 'done' for this 'do' ``` run: | ^~~~ ```

Check failure on line 23 in .github/workflows/async-update.yml

View workflow job for this annotation

GitHub Actions / actionlint

shellcheck reported issue in this script: SC1078:warning:33:24: Did you forget to close this double quoted string? ``` run: | ^~~~ ```

Check failure on line 23 in .github/workflows/async-update.yml

View workflow job for this annotation

GitHub Actions / actionlint

shellcheck reported issue in this script: SC1079:info:34:12: This is actually an end quote, but due to next char it looks suspect ``` run: | ^~~~ ```

Check failure on line 23 in .github/workflows/async-update.yml

View workflow job for this annotation

GitHub Actions / actionlint

shellcheck reported issue in this script: SC1062:error:43:3: Expected 'done' matching previously mentioned 'do' ``` run: | ^~~~ ```

Check failure on line 23 in .github/workflows/async-update.yml

View workflow job for this annotation

GitHub Actions / actionlint

shellcheck reported issue in this script: SC1072:error:43:5: Unexpected keyword/token. Fix any mentioned problems and try again ``` run: | ^~~~ ```
branch_name="${ref##*/}"
# default branch from env
[[ -z "${DEFAULT_BRANCH}" ]] && { echo "ERROR: DEFAULT_BRANCH not set, cannot continue." ; exit 1 ; }
commits_async_branch="commits.log"
# get log with all commits, go back maximum 100 commits
GIT_DIR=${GITHUB_REPOSITORY} git log --decorate=short "${ref}" > "${commits_async_branch}"
# now we go through the commits
# remember the current commit on this branch
current_commit_sha=
# the commit hash it was cherry-picked from
linked_commit_sha=
while read -r line ; do
if [[ "${line}" == "commit *" ]] ; then
# this means we ran into a new commit without finding a linked SHA in between, break here
[[ -n "${current_commit_sha}" && -z "${linked_commit_sha}" ]] && break
current_commit_sha=$(echo "${line}" | cut -f 2 -d ' ')
linked_commit_sha=""
continue
fi
# no current commit, simply continue
[[ -z "${current_commit_sha}" ]] && continue
# if we find a linked SHA in the commit message, this was a cherry pick and we do the actual work
if [[ "${line}" == "*cherry picked from commit*" ]] ; then
linked_commit_sha=${line##from commit }"
pr_url=$(gh --repo "${GITHUB_REPOSITORY}" pr list --search "${linked_commit_sha}" --json html_url --jq '.[].html_url')
if [[ -z "${pr_url}" ]] ; then
echo "Publish this without a linked PR"
else
# remove the label (if any)
gh --repo "${GITHUB_REPOSITORY}" pr edit "${pr_url}" --remove-label "${branch_name}""
echo "Publish this with linked PR"
fi
# reset the SHAs
current_commit_sha=""
linked_commit_sha=""
fi
done < ${commits_async_branch}

0 comments on commit e4b0e50

Please sign in to comment.