From df03a946e04f4e6753851a9a6b3b7b0de82f37a8 Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Tue, 22 Feb 2022 10:54:04 +0000 Subject: [PATCH] Fix 3rd party license updater (#92) Instead of pushing directly (since the main branch is protected) this creates a pull request --- .../workflows/update_3rd_party_licenses.sh | 23 +++++++++++++++---- .../workflows/update_3rd_party_licenses.yml | 2 ++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/update_3rd_party_licenses.sh b/.github/workflows/update_3rd_party_licenses.sh index e45e1ea..7ab6518 100755 --- a/.github/workflows/update_3rd_party_licenses.sh +++ b/.github/workflows/update_3rd_party_licenses.sh @@ -4,10 +4,25 @@ set -eux git config user.name "GitHub Actions" git config user.email "actions@user.noreply.github.com" -git checkout main +BRANCH=feature/3rd-party-licenses-update + +if git branch -a | grep "$BRANCH" > /dev/null; then + # already exists + exit +fi + +git fetch origin +git checkout -b "$BRANCH" npm run licenses -git add 3RD_PARTY_LICENSES -git commit -m "Update 3rd party licenses" || true -git push origin +if ! git diff --exit-code 1> /dev/null ; then + # there's stuff to push + git add 3RD_PARTY_LICENSES + git commit -m "Update 3rd party licenses" + git push origin "$BRANCH" + + gh pr create --fill \ + --title "Update 3rd party licenses (automation)" \ + --body "This is an automated action to update the action's 3rd party licenses" +fi diff --git a/.github/workflows/update_3rd_party_licenses.yml b/.github/workflows/update_3rd_party_licenses.yml index 25a949a..5da8dd5 100644 --- a/.github/workflows/update_3rd_party_licenses.yml +++ b/.github/workflows/update_3rd_party_licenses.yml @@ -17,3 +17,5 @@ jobs: node-version: '14' - run: ./.github/workflows/update_3rd_party_licenses.sh + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}