Skip to content

Commit b2630f2

Browse files
authored
ci: update workflows to follow our new guidelines for gh actions (#1250)
minimize permissions needed, differentiate between event based and reusable workflows Refs: equinor/ecalc-internal#1253
1 parent 953f84f commit b2630f2

File tree

9 files changed

+79
-41
lines changed

9 files changed

+79
-41
lines changed
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
name: Pre CI
1+
name: Ensure Code Quality
22

33
on:
4-
# Workflow dispatch is used for manual triggers
54
workflow_dispatch:
6-
# Workflow call is used for called from another workflow
75
workflow_call:
86

7+
permissions: {}
8+
99
env:
1010
UV_SYSTEM_PYTHON: 1
1111

1212
jobs:
13-
pre-commit: # Static analyzers, formatters and verifying pre-commit hooks has been run for both API and Web
13+
run-pre-commit-hooks:
14+
permissions:
15+
contents: read
1416
name: Build & Run Pre Commit hooks to verify code structure, quality etc. from pre-commit hooks
1517
runs-on: ubuntu-24.04
1618
steps:
Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "On push to any branch"
1+
name: "On push to any branch (not main)"
22

33
on:
44
push:
@@ -7,19 +7,29 @@ on:
77
tags-ignore:
88
- '**'
99

10+
permissions: {}
11+
1012
concurrency:
1113
group: ${{ github.workflow }}-${{ github.ref }}
1214
cancel-in-progress: true
1315

1416
jobs:
15-
pre-ci:
16-
uses: ./.github/workflows/pre-ci.yml
17+
ensure-code-quality:
18+
permissions:
19+
contents: read
20+
uses: ./.github/workflows/ensure-code-quality.yml
1721

18-
lib-ci:
19-
uses: ./.github/workflows/lib-ci.yml
22+
test-library:
23+
permissions:
24+
contents: read
25+
uses: ./.github/workflows/test-library.yml
2026

21-
examples-ci:
22-
uses: ./.github/workflows/examples-ci.yml
27+
test-example-notebooks:
28+
permissions:
29+
contents: read
30+
uses: ./.github/workflows/test-example-notebooks.yml
2331

24-
docs-ci:
25-
uses: ./.github/workflows/docs-ci.yml
32+
test-docs:
33+
permissions:
34+
contents: read
35+
uses: ./.github/workflows/test-docs.yml

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
name: "Main CI/CD"
1+
name: "On push to main"
22
on:
33
push:
44
branches:
55
- main
66

7+
permissions: {}
8+
79
jobs:
810

911
# NOTE: This job is needed in order to register a deployment in github (for a given environment), here libecalc-test. We need that in order
@@ -16,14 +18,20 @@ jobs:
1618
- name: dummy
1719
run: echo "Deployed"
1820

19-
pre-ci:
20-
uses: ./.github/workflows/pre-ci.yml
21+
ensure-code-quality:
22+
permissions:
23+
contents: read
24+
uses: ./.github/workflows/ensure-code-quality.yml
2125

22-
lib-ci:
23-
uses: ./.github/workflows/lib-ci.yml
26+
test-library:
27+
permissions:
28+
contents: read
29+
uses: ./.github/workflows/test-library.yml
2430

25-
docs-publish:
26-
uses: ./.github/workflows/docs-publish.yml
31+
publish-docs:
32+
permissions:
33+
contents: write
34+
uses: ./.github/workflows/publish-docs.yml
2735
secrets: inherit
2836

2937
# trigger-external-workflow:
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
name: Generate documentation
1+
name: Generate and publish documentation
22

33
on:
4-
# Workflow dispatch is used for manual triggers
54
workflow_dispatch:
6-
# Workflow call is used for called from another workflow
75
workflow_call:
86

7+
permissions: {}
8+
99
env:
1010
GITHUB_PAGES_BRANCH: gh-pages
1111

1212
jobs:
1313
publish-docs:
14+
permissions:
15+
contents: write # Needed to push to gh-pages branch
1416
runs-on: ubuntu-24.04
1517

1618
environment:
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ on:
1616
# NOTE!: When using Trusted Publishing to PyPI, we cannot do that from within a reusable workflow, therefore
1717
# we make it independent, and trigger it with published event from release-please workflow, instead of calling explicitly.
1818

19+
permissions: {}
20+
1921
jobs:
20-
check-release-created:
22+
check-release-created: # Parses JSON file from release-please workflow to see if a release was created
2123
permissions:
2224
actions: read # to dl artifacts from triggering workflow
25+
contents: read
2326
runs-on: ubuntu-24.04
2427
steps:
2528
- name: Download release-please outputs
@@ -38,7 +41,7 @@ jobs:
3841
echo "release_created=$(cat outputs.json | jq -r '.release_created')" >> $GITHUB_OUTPUT
3942
outputs:
4043
release-created: ${{ steps.release-created.outputs.release_created }}
41-
publish:
44+
publish-libecalc-to-pypi:
4245
needs: check-release-created
4346
if: ${{ needs.check-release-created.outputs.release-created == 'true' }}
4447
environment:
@@ -48,6 +51,7 @@ jobs:
4851
#url: https://test.pypi.org/p/libecalc # NOTE: If/when we need to test publishing etc to PyPI, we can use Test PyPI
4952
permissions:
5053
id-token: write # Required for Trusted Publishing to PyPI, the pypa action uses this
54+
contents: read
5155
runs-on: ubuntu-24.04
5256
steps:
5357
- name: Checkout code

.github/workflows/release-please.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
name: release-please
22

33
on:
4-
workflow_dispatch: # Workflow dispatch is used for manual triggers.
4+
workflow_dispatch:
55
workflow_run:
6-
workflows: [ "Main CI/CD" ]
6+
workflows: [ "On push to main" ]
77
types:
88
- completed
99

10+
permissions: {}
11+
1012
jobs:
1113
release-please:
12-
permissions: write-all
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
issues: write
1318
runs-on: ubuntu-24.04
1419
steps:
1520
- uses: googleapis/release-please-action@v4
@@ -23,6 +28,8 @@ jobs:
2328

2429
create-output-artifact:
2530
needs: release-please
31+
permissions:
32+
contents: read
2633
runs-on: ubuntu-24.04
2734
steps:
2835
- name: Create output directory
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
name: Test Docs
1+
name: Build and Test Docs
22

33
on:
4-
# Workflow dispatch is used for manual triggers
54
workflow_dispatch:
6-
# Workflow call is used for called from another workflow
75
workflow_call:
86

7+
permissions: {}
8+
99
jobs:
10-
publish-docs:
10+
build-docs:
11+
permissions:
12+
contents: read
1113
runs-on: ubuntu-24.04
1214

1315
steps:

.github/workflows/examples-ci.yml renamed to .github/workflows/test-example-notebooks.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
name: Example Notebooks CI
1+
name: Test Example Notebooks
22
on:
3-
# Workflow dispatch is used for manual triggers
43
workflow_dispatch:
5-
# Workflow call is used for called from another workflow
64
workflow_call:
75

6+
permissions: {}
7+
88
jobs:
9-
run-tests:
9+
test-example-notebooks:
10+
permissions:
11+
contents: read
1012
runs-on: ubuntu-24.04
1113
steps:
1214
- name: Checkout code
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
name: CLI CI (Build and test)
1+
name: Test Library
22
on:
3-
# Workflow dispatch is used for manual triggers
43
workflow_dispatch:
5-
# Workflow call is used for called from another workflow
64
workflow_call:
75

8-
# TODO: BuildX and publish to use as in order for web to always be able to fetch image to matching branch?
6+
permissions: {}
7+
98
jobs:
10-
run-tests:
9+
test-library:
10+
permissions:
11+
contents: read
1112
runs-on: ubuntu-24.04
1213
strategy:
1314
fail-fast: false

0 commit comments

Comments
 (0)