Skip to content

Commit e16225e

Browse files
committed
ci: trigger publish via on_workflow_run event
It is the only way to set the correct "owner workflow", as it is not embedded in another, as when using workflow_call. Refs: equinor/ecalc-internal#433
1 parent 0326512 commit e16225e

4 files changed

Lines changed: 22 additions & 25 deletions

File tree

.github/workflows/on-push-main-branch.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ jobs:
2626
uses: ./.github/workflows/docs-publish.yml
2727
secrets: inherit
2828

29-
release-please:
30-
uses: ./.github/workflows/release-please.yml
31-
secrets: inherit
29+
# NOTE: We trigger release-please in the on_workflow_run instead, freeing it from this workflow,
30+
# and creating a separate workflow for it, that we again can listen to and trigger the publish workflow from.
31+
# Also, we want to build and test the library before we trigger the release-please workflow,
32+
# so that we can be sure that the library is in a good state before we release it, and instead of doing it twice,
33+
# we wait until that is done on the main branch first.

.github/workflows/publish.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ name: Publish libeCalc package to PyPI
22

33
on:
44
workflow_run:
5-
workflows: [trigger-publish]
5+
workflows: [release-please]
66
types:
77
- completed
8-
# Note! We cannot trigger on published event, since that can only be triggered when done manually.
8+
# Note! We cannot trigger on published event, since that can only be triggered when done manually (or with a
9+
# separate PAT token, not the standard GITHUB_TOKEN), and we want to use the standard GITHUB_TOKEN).
910
# Therefore we trigger this workflow independently, after the trigger-publish workflow has run, in
1011
# order for this workflow to be the owner of the PyPI publishing job, and can be verified. This limits
1112
# us to only allow this workflow to be allowed to publish to PyPI trustedly.
@@ -17,6 +18,8 @@ on:
1718

1819
jobs:
1920
publish:
21+
# NOTE: Only run if release-please creates a release, ie. it successfully ends
22+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
2023
environment:
2124
name: pypi
2225
url: https://pypi.org/project/libecalc/

.github/workflows/release-please.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ name: release-please
22

33
on:
44
workflow_dispatch: # Workflow dispatch is used for manual triggers.
5-
workflow_call: # Workflow call is used for called from another workflow.
5+
workflow_run:
6+
workflows: [ on-push-main-branch ]
7+
types:
8+
- completed
69

710
jobs:
811
release-please:
@@ -18,7 +21,11 @@ jobs:
1821
release_created: ${{ steps.release.outputs.release_created }}
1922
tag_name: ${{ steps.release.outputs.tag_name }}
2023

21-
deploy_prod:
22-
needs: release-please
23-
uses: ./.github/workflows/trigger-publish.yml
24-
if: ${{ needs.release-please.outputs.release_created }}
24+
no-release-created:
25+
if: ${{ needs.release-please.outputs.release_created == 'false' }}
26+
runs-on: ubuntu-24.04
27+
steps:
28+
- name: No release created
29+
run: |
30+
echo "No release created, setting output to false, to avoid triggering publish workflow."
31+
exit 1

.github/workflows/trigger-publish.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)