Skip to content

Commit 0f9ffe6

Browse files
yaswantjames-bruten-mojennyhickson
authored
Enhance reusable workflows (#80)
Co-authored-by: James Bruten <109733895+james-bruten-mo@users.noreply.github.com> Co-authored-by: Jenny Hickson <61183013+jennyhickson@users.noreply.github.com>
1 parent 4320a68 commit 0f9ffe6

23 files changed

Lines changed: 493 additions & 163 deletions

.github/dependabot.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# ------------------------------------------------------------------------------
2+
# (c) Crown copyright Met Office. All rights reserved.
3+
# The file LICENCE, distributed with this code, contains details of the terms
4+
# under which the code may be used.
5+
# ------------------------------------------------------------------------------
6+
#
7+
# ==============================================================================
8+
# Dependabot Configuration
9+
#
10+
# This configuration automates security updates for third-party GitHub Actions.
11+
# To protect our downstream consumers, all actions must be pinned to a
12+
# 40-character commit SHA rather than a mutable version tag.
13+
#
14+
# Custom rulesets in place:
15+
# 1. Monthly Schedule: Checks for updates once a month to minimize noise.
16+
# 2. Major Version Lock: Automated major updates (e.g., v9 to v10) are blocked
17+
# to prevent unexpected breaking code changes.
18+
# 3. PR Grouping: All discovered minor/patch updates are bundled into a single
19+
# monthly Pull Request instead of flooding the repository notifications.
20+
#
21+
# How to manually trigger a Major Update:
22+
# To safely upgrade an action to its next major version baseline:
23+
# 1. Open the workflow file.
24+
# 2. Leave the old SHA exactly as it is, but manually change the trailing
25+
# comment tag to the new target baseline version (e.g., update the text
26+
# from "# v4.0.0" to "# v5.0.0").
27+
# 3. Push your change. Dependabot will instantly recognize the target update
28+
# and generate a new PR containing the correct, matching v5 commit hash.
29+
# ==============================================================================
30+
31+
version: 2
32+
updates:
33+
# Enable automatic tracking for GitHub Actions dependencies
34+
- package-ecosystem: "github-actions"
35+
directory: "/"
36+
schedule:
37+
interval: "monthly"
38+
cooldown:
39+
default-days: 7
40+
41+
# Ignore rules to block major version jumps
42+
ignore:
43+
- dependency-name: "*"
44+
update-types: ["version-update:semver-major"]
45+
46+
groups:
47+
# Group all action updates into a single PR to reduce noise
48+
# Rule applies across every single third-party action used in all workflows
49+
github-actions-dependencies:
50+
patterns:
51+
- "*"

.github/pull_request_template.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# PR Summary
22

3+
<!-- One-line Summary -->
4+
35
Code Reviewer: <!-- CR id, filled by SSD -->
46

57
<!-- To be completed by the developer -->
68

7-
<!-- Provide a brief description of the changes in this PR, including any notes
8-
useful for reviewers -->
9+
<!-- Provide a brief description of the changes in this PR, including any notes useful for reviewers -->
910

10-
## Code Quality Checklist
11+
## :white_check_mark: Code Quality Checklist
1112

1213
(_Some checks are automatically carried out via the CI pipeline_)
1314

@@ -16,16 +17,12 @@ Code Reviewer: <!-- CR id, filled by SSD -->
1617
- [ ] The modified workflow's README has been updated, if required
1718
- [ ] The changes have been sufficiently tested (please describe)
1819

19-
## AI Assistance and Attribution
20+
## :robot: AI Assistance and Attribution
2021

21-
- [ ] Some of the content of this change has been produced with the assistance
22-
of _Generative AI tool name_ (e.g., Met Office Github Copilot Enterprise,
23-
Github Copilot Personal, ChatGPT GPT-4, etc) and I have followed the
24-
[Simulation Systems AI policy](https://metoffice.github.io/simulation-systems/FurtherDetails/ai.html)
25-
(including attribution labels)
22+
- [ ] Some of the content of this change has been produced with the assistance of _Generative AI tool name_ (e.g., Met Office GitHub Copilot Enterprise, GitHub Copilot Personal, ChatGPT GPT-4, etc) and I have followed the [Simulation Systems AI policy](https://metoffice.github.io/simulation-systems/FurtherDetails/ai.html) (including attribution labels)
2623

2724
<!-- If AI has been used, please provide more details here -->
2825

29-
# Code Review
26+
## :computer: Code Review
3027

31-
- [ ] The changes are approriate and testing has been sufficient
28+
- [ ] The changes are appropriate and testing has been sufficient

.github/workflows/build-sphinx-docs.yaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ on:
1616
default: 'documentation'
1717
requirements:
1818
description: 'Path to the requirements file to install dependencies from'
19-
required: true
19+
required: false
2020
type: string
2121
default: 'requirements.txt'
2222
sphinx-opts:
@@ -40,22 +40,31 @@ on:
4040
type: number
4141
default: 5
4242

43+
permissions:
44+
contents: read
45+
4346
jobs:
4447
build-sphinx-docs:
4548
name: Build Sphinx Docs
4649
runs-on: ${{ inputs.runner }}
4750
timeout-minutes: ${{ inputs.timeout }}
51+
permissions:
52+
contents: read # Required to read repository file configurations
53+
pages: write # Required to deploy to GitHub Pages
54+
4855
env:
4956
DOCS_DIR: ${{ inputs.docs-directory }}
5057
REQS_FILE: ${{ inputs.requirements }}
5158
SPHINX_OPTS: ${{ inputs.sphinx-opts }}
5259
BUILD_DIR: ${{ inputs.build-directory }}
5360
steps:
5461
- name: Checkout repository
55-
uses: actions/checkout@v6
62+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
63+
with:
64+
persist-credentials: false
5665

5766
- name: Set up Python 3.12
58-
uses: actions/setup-python@v6
67+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
5968
with:
6069
python-version: '3.12'
6170
cache: 'pip'
@@ -80,7 +89,7 @@ jobs:
8089
8190
- name: Upload artifact to GitHub Pages
8291
if: ${{ (github.event_name == 'push' || github.event_name == 'merge_group') && github.ref_name == 'main'}}
83-
uses: actions/upload-pages-artifact@v4
92+
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
8493
with:
8594
name: github-pages
8695
path: "$BUILD_DIR/html"
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# ------------------------------------------------------------------------------
2+
# (c) Crown copyright Met Office. All rights reserved.
3+
# The file LICENCE, distributed with this code, contains details of the terms
4+
# under which the code may be used.
5+
# ------------------------------------------------------------------------------
6+
17
name: Track Review Project
28

39
on:
@@ -7,12 +13,20 @@ on:
713
- completed
814
workflow_dispatch:
915

16+
# Best Practice: Explicitly strip all top-level default permissions
17+
permissions: {}
18+
1019
jobs:
1120
track_review_project:
21+
# Granular permissions are safely locked directly to this specific execution context
22+
permissions:
23+
actions: read # Required to view the status of the upstream triggered workflow run
24+
repository-projects: write # Required to add or mutate tasks inside GitHub Project 376
1225
uses: MetOffice/growss/.github/workflows/track-review-project.yaml@main
13-
secrets: inherit
26+
secrets:
27+
PROJECT_ACTION_PAT: ${{ secrets.PROJECT_ACTION_PAT }}
1428
# Optional inputs (with default values)
1529
with:
16-
runner: "ubuntu-22.04"
30+
runner: "ubuntu-slim"
1731
project_org: "MetOffice"
1832
project_number: 376

.github/workflows/call-trigger-project-workflow.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# ------------------------------------------------------------------------------
2+
# (c) Crown copyright Met Office. All rights reserved.
3+
# The file LICENCE, distributed with this code, contains details of the terms
4+
# under which the code may be used.
5+
# ------------------------------------------------------------------------------
6+
17
name: Trigger Review Project
28

39
on:
@@ -6,7 +12,11 @@ on:
612
pull_request_review:
713
pull_request_review_comment:
814

15+
permissions: {}
16+
917
jobs:
1018
trigger_project_workflow:
19+
permissions:
20+
contents: read # Required for checking out code or referencing internal workflow actions
21+
pull-requests: write # Required to modify or comment on pull requests within this pipeline process
1122
uses: MetOffice/growss/.github/workflows/trigger-project-workflow.yaml@main
12-
secrets: inherit

.github/workflows/check-cr-approved.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ name: Check CR Approval
99
on:
1010
workflow_call:
1111

12-
permissions: read-all
12+
permissions:
13+
contents: read # Required to evaluate metadata from the triggering GitHub event context
14+
pull-requests: read # Required to check the PR reviews and approval status
1315

1416
jobs:
1517
cr_check:
18+
name: CR Approval
1619
runs-on: ubuntu-24.04
1720
timeout-minutes: 2
1821

@@ -24,6 +27,12 @@ jobs:
2427
REPO: ${{ github.repository }}
2528
GH_TOKEN: ${{ github.token }}
2629
run: |
30+
# Ensure context variables are present, don't run from a non-PR event
31+
if [[ -z "$PR_NUMBER" ]]; then
32+
echo "::error::This workflow must be triggered by a pull_request event."
33+
exit 1
34+
fi
35+
2736
echo "Running on PR #$PR_NUMBER in Repository $REPO"
2837
2938
# -- 1. Extract the assigned Code Reviewer from the PR body

0 commit comments

Comments
 (0)