Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Dispatch patch tag workflow instead of running directly #139

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 37 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,7 @@ jobs:
name: Check governance
runs-on: ubuntu-latest
needs: 'genmatrix'
if: ${{ github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
GuySartorelli marked this conversation as resolved.
Show resolved Hide resolved
outputs:
can_tag: ${{ steps.check-governance.outputs.can_tag }}
env:
Expand Down Expand Up @@ -1032,33 +1033,43 @@ jobs:
echo "can_tag output is $CAN_TAG"
echo "can_tag=$CAN_TAG" >> $GITHUB_OUTPUT

gaugerelease:
name: Check unreleased changes
dispatchtagpatchrelase:
name: Dispatch tag patch release
runs-on: ubuntu-latest
needs: [tests, checkgovernance]
if: ${{ needs.checkgovernance.outputs.can_tag == '1' && (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') }}
outputs:
do_release: ${{ steps.gauge-release.outputs.do_release }}
next_tag: ${{ steps.gauge-release.outputs.next_tag }}
if: ${{ (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && needs.checkgovernance.outputs.can_tag == '1' }}
env:
GITHUB_REPOSITORY: ${{ github.repository }}
BRANCH: ${{ github.ref_name }}
steps:
- name: Gauge release
id: gauge-release
uses: silverstripe/gha-gauge-release@v1
with:
latest_local_sha: ${{ needs.tests.outputs.latest_local_sha }}

patchrelease:
name: Patch release
runs-on: ubuntu-latest
needs: gaugerelease
if: ${{ needs.gaugerelease.outputs.do_release == '1' }}
permissions:
contents: write
steps:
- name: Patch release
uses: silverstripe/gha-tag-release@v1
with:
tag: ${{ needs.gaugerelease.outputs.next_tag }}
delete_existing: false
release: true
release_auto_notes: true
- name: Dispatch tag patch release
shell: bash
id: dispatch-tag-patch-release
run: |
if ! [[ -f .github/workflows/tag-patch-release.yml ]]; then
echo "tag-patch-release.yml not present. Skipping."
exit 0
fi
GuySartorelli marked this conversation as resolved.
Show resolved Hide resolved
# https://docs.github.com/en/rest/actions/workflows?apiVersion=2022-11-28#create-a-workflow-dispatch-event
RESP_CODE=$(curl -w %{http_code} -s -L -o __response.json \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$GITHUB_REPOSITORY/actions/workflows/tag-patch-release.yml/dispatches \
-d "{\"ref\":\"$BRANCH\",\"inputs\":{\"latest_local_sha\":\"${{ needs.tests.outputs.latest_local_sha }}\"}}"
)
if [[ $RESP_CODE != "204" ]]; then
echo "Failed to dispatch workflow - 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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ on:
pull_request:
workflow_dispatch:

permissions: {}

jobs:
ci:
name: CI
permissions:
pull-requests: read
contents: read
Comment on lines +29 to +31
Copy link
Member Author

@GuySartorelli GuySartorelli Jul 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore the fact that CI there is still red - that's just 'cause there's nothing for generate-matrix to output for that repo, and CI doesn't like having no matrix when it's told there will be one.

I also tested these permissions in a repo that actually does get a generated matrix and it works as expected, red job not-withstanding

uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1
```

Expand All @@ -35,9 +40,14 @@ on:
schedule:
- cron: '0 0 * * 1'

permissions: {}

jobs:
ci:
name: CI
permissions:
pull-requests: read
contents: read
# Only run the cron on the account hosting this repository, not on the accounts of forks
# Change '<account_name>' to match the name of the account hosting this repository
if: (github.event_name == 'schedule' && github.repository_owner == '<account_name>') || (github.event_name != 'schedule')
Expand Down
Loading