Skip to content

Break workflow up: a reusable workflow using reusable actions #69

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

Merged
merged 2 commits into from
Jul 4, 2025

Conversation

rtyley
Copy link
Member

@rtyley rtyley commented Jun 25, 2025

This change enables a lot of code-reuse with the new Gradle release workflow:

Changes

  • The bulk of the reusable workflow file has been extracted into a suite of 7 GitHub Actions (specifically composite actions), each of which correspond to the 7 existing jobs in the flow.
    • As GitHub Actions have a convention that their parameters are 'dash-case', a lot of the parameters have switched from snake-case (release_type ...with an underscore) to dash-case (release-type ...with a hyphen). This change means that we should probably make the next release of gha-scala-library-release-workflow have a major-version-bump, eg to v3.
    • The 5 global environment variables in the reusable workflow have been removed, to improve encapsulation of the 7 GitHub Actions - ie to be. more explicit about what inputs they're actually using.
    • Unfortunately there's no easy way to express that a GitHub Action should run using the same commit as the reusable-workflow file that called it (tho' it is possible for workflow-to-workflow). Consequently for this PR, all the references to those GitHub actions have a @break-workflow-up-into-smaller-reusable-files reference - which needs to be switched to @main before merge
  • For passing files between jobs, we switch from using GitHub Actions caching infrastructure to using artifacts. Using caching was always a bit of a hack, and this change means we don't have to try to come up with unique cache keys.

For composite actions (unlike reusable workflows), we can access github.action_path from the github context, and get files from our repo that way.

Testing

@rtyley rtyley force-pushed the break-workflow-up-into-smaller-reusable-files branch 5 times, most recently from d130e30 to 24367db Compare July 1, 2025 16:32
rtyley added a commit that referenced this pull request Jul 1, 2025
This reverts commit 24367db.

See this and the subsequent comment:

#69 (comment)

When we manually use `actions/checkout` to get an action, _it makes us responsible for finding a safe folder_
to checkout the GitHub action- when we let the GitHub Actions system do it for us,
the _system_ is responsible for doing it.

So, I think that means I prefer the 'system checkout' syntax:

```yml
      - id: init
        uses: guardian/gha-scala-library-release-workflow/actions/init@break-workflow-up-into-smaller-reusable-files
```

...rather than the 'manual checkout' syntax:

```yml
      - uses: actions/checkout@v4
        with:
          repository: guardian/gha-scala-library-release-workflow # TODO - adapt for forks
          ref: ${{ ACTION_BRANCH }}
      - id: init
        uses: ./.github/actions/init
```

...even though the 'manual checkout' syntax lets us configure the `ACTION_BRANCH` in just one place.
@rtyley rtyley force-pushed the break-workflow-up-into-smaller-reusable-files branch 13 times, most recently from 1bc81d4 to 890711c Compare July 2, 2025 13:57
@rtyley rtyley force-pushed the break-workflow-up-into-smaller-reusable-files branch 11 times, most recently from 17225a6 to 4074d5c Compare July 3, 2025 10:29
steps:
- uses: actions/setup-java@v4
- id: act
uses: guardian/gha-scala-library-release-workflow/actions/init@break-workflow-up-into-smaller-reusable-files
Copy link
Member Author

@rtyley rtyley Jul 3, 2025

Choose a reason for hiding this comment

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

Before merge, we need to switch this - and the other invocations of our actions - to no longer point to the break-workflow-up-into-smaller-reusable-files branch.

Where should it point?! Maybe we should point to main - and when we cut a release, switch it to v2 or v3?!

Suggested change
uses: guardian/gha-scala-library-release-workflow/actions/init@break-workflow-up-into-smaller-reusable-files
uses: guardian/gha-scala-library-release-workflow/actions/init@main

@rtyley rtyley force-pushed the break-workflow-up-into-smaller-reusable-files branch from 4074d5c to 6d477bd Compare July 3, 2025 13:55
@rtyley rtyley marked this pull request as ready for review July 3, 2025 15:02
@rtyley rtyley requested a review from a team as a code owner July 3, 2025 15:02
Copy link
Contributor

@JamieB-gu JamieB-gu left a comment

Choose a reason for hiding this comment

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

Looks good!

shell: bash
env:
GH_TOKEN: ${{ steps.generate-github-app-token.outputs.token }}
GH_REPO: ${{ github.repository }}
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this used for?

@rtyley rtyley force-pushed the break-workflow-up-into-smaller-reusable-files branch from 9fcb996 to 5d9e4a5 Compare July 3, 2025 21:56
rtyley added a commit that referenced this pull request Jul 4, 2025
@rtyley rtyley force-pushed the break-workflow-up-into-smaller-reusable-files branch from 60aa859 to dc7b7e6 Compare July 4, 2025 11:57
@rtyley rtyley changed the title Break workflow up into smaller reusable files Break workflow up: a reusable workflow using reusable actions Jul 4, 2025
@rtyley rtyley force-pushed the break-workflow-up-into-smaller-reusable-files branch from dc7b7e6 to 644e8ff Compare July 4, 2025 14:03
This change enables a lot of code-reuse with the new Gradle release workflow:

* guardian#1

## Changes

* The bulk of the reusable workflow file has been extracted into a suite of 7 GitHub _Actions_ (specifically [composite actions](https://docs.github.com/en/actions/tutorials/creating-a-composite-action)), each of which correspond to the 7 existing jobs in the flow.
  * As GitHub Actions have a convention that their parameters are 'dash-case', a lot of the parameters have switched from snake-case (`release_type` - with an underscore) to dash-case (`release-type` - with a hyphen). This change means that we should probably
  * The 5 global environment variables in the reusable workflow have been removed, to improve encapsulation of the 7 GitHub Actions - ie to be. more explicit about what inputs they're actually using.
  * Unfortunately there's [no](https://github.com/orgs/community/discussions/18601#discussioncomment-13296390) easy way to express that a GitHub Action should run using the same commit as the reusable-workflow file that called it (tho' [it is possible for workflow-to-workflow](https://docs.github.com/en/actions/how-tos/sharing-automations/reusing-workflows#:~:text=If%20you%20use%20the%20second%20syntax%20option%20(without%20%7Bowner%7D/%7Brepo%7D%20and%20%40%7Bref%7D)%20the%20called%20workflow%20is%20from%20the%20same%20commit%20as%20the%20caller%20workflow.%20Ref%20prefixes%20such%20as%20refs/heads%20and%20refs/tags%20are%20not%20allowed.%20You%20cannot%20use%20contexts%20or%20expressions%20in%20this%20keyword.)). Consequently for this PR, all the references to those GitHub actions have a `@break-workflow-up-into-smaller-reusable-files` reference - which needs to be switched to `@main` before merge
* For passing files between jobs, we switch from using GitHub Actions _caching_ infrastructure to [using artifacts](https://docs.github.com/en/actions/how-tos/writing-workflows/choosing-what-your-workflow-does/storing-and-sharing-data-from-a-workflow#comparing-artifacts-and-dependency-caching). Using caching was always a bit of a hack, and this change means we don't have to try to come up with unique cache keys.
* Everything in the '🔒 Update GitHub' Action needs the `GH_REPO` & `GH_TOKEN` environment variables, so I've added them to the env in the `Common Values`
  section, and moved that step to the start.

For [composite actions](https://docs.github.com/en/actions/tutorials/creating-a-composite-action) (unlike reusable workflows), we can [access `github.action_path`](https://github.com/orgs/community/discussions/32593#discussioncomment-3616375) from the [`github` context](https://docs.github.com/en/actions/reference/accessing-contextual-information-about-workflow-runs#github-context), and get files from our repo that way.

## Testing

* guardian/etag-caching#96
@rtyley rtyley force-pushed the break-workflow-up-into-smaller-reusable-files branch from 644e8ff to 41f0c0d Compare July 4, 2025 14:58
@rtyley
Copy link
Member Author

rtyley commented Jul 4, 2025

I'm happy this is now in a good state - I'm now going to:

  • Update the action branch references from @break-workflow-up-into-smaller-reusable-files to @main
  • Merge this PR
  • Make a new release of the workflow as v3 - I may need to do some figuring out about what the action references should be with a release.

@rtyley
Copy link
Member Author

rtyley commented Jul 4, 2025

  • Make a new release of the workflow as v3 - I may need to do some figuring out about what the action references should be with a release.

Actually, I've just realised that although I intended to update these two workflow parameters to use dash-case, I never got round to it in this PR! So the next release will actually be - I think - compatible (if inconsistent in it's use of dash-case) and so I will just release it as v2.0.2.

rtyley added a commit that referenced this pull request Jul 4, 2025
Sadly, on #69, I managed
to do lots of testing of Preview releases, but not any of full-main-branch releases - consequently
I missed that push-release-commit was missing an input parameter of `release-type` - I need a better linter for
GitHub Actions!

Example failure:

https://github.com/guardian/etag-caching/actions/runs/16078051367/job/45377631265
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants