From 5a8d7e15355bad4cafbc25fe80b1cc63abb71f06 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 13 Jun 2023 13:44:51 +1200 Subject: [PATCH 1/4] FIX Use correct type for title input --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index d450206..eb95ddb 100644 --- a/action.yml +++ b/action.yml @@ -6,7 +6,7 @@ inputs: type: string required: true title: - type: boolean + type: string required: true description: type: string From 33aeb69b97a0c11872750df60367f520666f3f60 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 16 Aug 2023 15:03:36 +1200 Subject: [PATCH 2/4] MNT Run module-standardiser --- .github/workflows/action-ci.yml | 11 +++++++++++ .github/workflows/keepalive.yml | 17 +++++++++++++++++ .github/workflows/merge-up.yml | 17 +++++++++++++++++ LICENSE | 29 +++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 .github/workflows/action-ci.yml create mode 100644 .github/workflows/keepalive.yml create mode 100644 .github/workflows/merge-up.yml create mode 100644 LICENSE diff --git a/.github/workflows/action-ci.yml b/.github/workflows/action-ci.yml new file mode 100644 index 0000000..3fd70a4 --- /dev/null +++ b/.github/workflows/action-ci.yml @@ -0,0 +1,11 @@ +name: Action CI + +on: + push: + pull_request: + workflow_dispatch: + +jobs: + actionci: + name: Action CI + uses: silverstripe/gha-action-ci/.github/workflows/action-ci.yml@v1 diff --git a/.github/workflows/keepalive.yml b/.github/workflows/keepalive.yml new file mode 100644 index 0000000..9d4bf00 --- /dev/null +++ b/.github/workflows/keepalive.yml @@ -0,0 +1,17 @@ +name: Keepalive + +on: + # At 8:40 PM UTC, on day 25 of the month + schedule: + - cron: '40 20 25 * *' + workflow_dispatch: + +jobs: + keepalive: + name: Keepalive + # Only run cron on the silverstripe account + if: (github.event_name == 'schedule' && github.repository_owner == 'silverstripe') || (github.event_name != 'schedule') + runs-on: ubuntu-latest + steps: + - name: Keepalive + uses: silverstripe/gha-keepalive@v1 diff --git a/.github/workflows/merge-up.yml b/.github/workflows/merge-up.yml new file mode 100644 index 0000000..1d895ac --- /dev/null +++ b/.github/workflows/merge-up.yml @@ -0,0 +1,17 @@ +name: Merge-up + +on: + # At 8:40 PM UTC, only on Wednesday + schedule: + - cron: '40 20 * * 3' + workflow_dispatch: + +jobs: + merge-up: + name: Merge-up + # Only run cron on the silverstripe account + if: (github.event_name == 'schedule' && github.repository_owner == 'silverstripe') || (github.event_name != 'schedule') + runs-on: ubuntu-latest + steps: + - name: Merge-up + uses: silverstripe/gha-merge-up@v1 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c36440d --- /dev/null +++ b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2023, Silverstripe Limited - www.silverstripe.com +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. From 82c4d1c2d09f6c5f02d660506a9911dfcf01a1e3 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 17 Aug 2023 17:57:13 +1200 Subject: [PATCH 3/4] FIX Use gha-trigger-ci --- action.yml | 60 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index eb95ddb..efc9651 100644 --- a/action.yml +++ b/action.yml @@ -32,18 +32,19 @@ runs: exit 1 fi - - name: Branch commit and pull-request + - name: Git operations + id: git-operations shell: bash env: BRANCH: ${{ inputs.branch }} TITLE: ${{ inputs.title }} - DESCRIPTION: ${{ inputs.description }} GITHUB_REPOSITORY: ${{ github.repository }} run: | # Escape double quotes '"' => '\"' TITLE=${TITLE//\"/\\\"} - DESCRIPTION=${DESCRIPTION//\"/\\\"} BASE_BRANCH=$(git rev-parse --abbrev-ref HEAD) + echo "BASE_BRANCH is $BASE_BRANCH" + echo "base_branch=$BASE_BRANCH" >> $GITHUB_OUTPUT # Run git commit, push and create pull-request as 'github-actions' user git config --local user.name "github-actions" # The 41898282+ email prefixed is the required, matches the ID here @@ -55,16 +56,56 @@ runs: git commit -m "$TITLE" git status git push --set-upstream origin "$BRANCH" + + # Trigger CI manually as the pull-request created using the GitHub API later will NOT trigger any new + # workflows e.g. ci.yml as a measure to protect against infinite loops + # https://github.com/peter-evans/create-pull-request/issues/48#issuecomment-537478081 + - name: Trigger CI + id: trigger-ci + uses: silverstripe/gha-trigger-ci@v1 + with: + branch: ${{ inputs.branch }} + validate_branch: false + + - name: Update description + id: update-description + shell: bash + env: + BRANCH: ${{ inputs.branch }} + DESCRIPTION: ${{ inputs.description }} + GITHUB_REPOSITORY: ${{ github.repository }} + run: | + # Escape / to %2F e.g. pulls/1.9/lorem => pulls%2F1.9%2Florem + ESCAPED_BRANCH=${BRANCH//\//%2F} + # Escape double quotes '"' => '\"' + UPDATED_DESRCRIPTION=${DESCRIPTION//\"/\\\"} + # Add a note to the pull-request description to explain where to find the CI workflow results + UPDATED_DESRCRIPTION=$(cat << EOF + $UPDATED_DESRCRIPTION\n\n---\n\nThis pull-request was created by a [GitHub Action](/silverstripe/gha-pull-request) and for GitHubs own security reasons cannot automatically trigger a subsequent CI workflow like it would if a human created the pull-request.\n\nInstead a CI workflow was created via the GitHub API. One shortcoming of doing this is the results of the CI workflow do not show above the merge button like they do on normal pull-requests.\n\n**BEFORE MERGING - View the CI workflow runs for the branch in this pull-request in this [filtered list](/$GITHUB_REPOSITORY/actions?query=branch%3A$ESCAPED_BRANCH).** + EOF + ) + echo "UPDATED_DESRCRIPTION is $UPDATED_DESRCRIPTION" + echo "updated_description=$UPDATED_DESRCRIPTION" >> $GITHUB_OUTPUT + + - name: Pull request + shell: bash + env: + BRANCH: ${{ inputs.branch }} + BASE_BRANCH: ${{ steps.git-operations.outputs.base_branch }} + TITLE: ${{ inputs.title }} + GITHUB_REPOSITORY: ${{ github.repository }} + UPDATED_DESRCRIPTION: ${{ steps.update-description.outputs.updated_description }} + run: | # Create new pull-request via GitHub API # https://docs.github.com/en/rest/reference/pulls#create-a-pull-request - RESP_CODE=$(curl -w %{http_code} -s -o /dev/null \ + RESP_CODE=$(curl -w %{http_code} -s -o __response.json \ -X POST https://api.github.com/repos/$GITHUB_REPOSITORY/pulls \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: token ${{ github.token }}" \ -d @- << EOF { "title": "$TITLE", - "body": "$DESCRIPTION", + "body": "$UPDATED_DESRCRIPTION", "head": "$BRANCH", "base": "$BASE_BRANCH" } @@ -74,5 +115,14 @@ runs: echo "New pull-request created" else echo "Fail to create pull-request - HTTP response code was $RESP_CODE" + cat __response.json exit 1 fi + + - name: Delete temporary files + shell: bash + if: always() + run: | + if [[ -f __response.json ]]; then + rm __response.json + fi From b2d449d8dce2a9e7d54e3245dd12cf27a15369c8 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 22 Aug 2023 16:30:19 +1200 Subject: [PATCH 4/4] MNT Run module-standardiser --- .github/workflows/auto-tag.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/auto-tag.yml b/.github/workflows/auto-tag.yml index 17712c8..32801df 100644 --- a/.github/workflows/auto-tag.yml +++ b/.github/workflows/auto-tag.yml @@ -3,6 +3,7 @@ on: push: tags: - '*.*.*' + workflow_dispatch: jobs: auto-tag: name: Auto-tag