Skip to content

Commit b110827

Browse files
committed
cicd: change pypi publishing to trusted publisher
Adding an Equinor user to avoid relying on single indivisuals, and avoid pwd/token with trusted publishing. Refs: equinor/ecalc-internal#433
1 parent 76adb32 commit b110827

2 files changed

Lines changed: 15 additions & 33 deletions

File tree

.github/workflows/publish.yml

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,23 @@ name: Publish libeCalc package to PyPI
22

33
on:
44
workflow_call:
5-
secrets:
6-
PYPI_TOKEN:
7-
required: true
8-
9-
workflow_dispatch: # Trigger manually, if needed
10-
11-
permissions:
12-
packages: write
13-
contents: read
14-
id-token: write
5+
workflow_dispatch:
156

167
jobs:
178
publish:
9+
environment:
10+
name: pypi
11+
url: https://pypi.org/project/libecalc/
12+
#name: testpypi
13+
#url: https://test.pypi.org/p/libecalc # NOTE: If/when we need to test publishing etc to PyPI, we can use Test PyPI
14+
permissions:
15+
id-token: write # Required for Trusted Publishing to PyPI, the pypa action uses this
1816
runs-on: ubuntu-24.04
1917
steps:
2018
- name: Checkout code
2119
uses: actions/checkout@v4
2220
with:
23-
# Make sure we publish from main branch, not the triggering ref
21+
# NOTE: Make sure we publish from main branch, not the triggering ref
2422
ref: ${{ github.event.repository.default_branch }}
2523

2624
- name: Setup Python 3.11
@@ -33,26 +31,12 @@ jobs:
3331
version: 1.8.4
3432
virtualenvs-create: true
3533

36-
- name: Check pyproject.toml validity
37-
run: poetry check --no-interaction
38-
39-
- name: Cache dependencies
40-
id: cache-deps
41-
uses: actions/cache@v4
42-
with:
43-
path: ${{github.workspace}}/.venv
44-
key: poetry-${{ hashFiles('**/poetry.lock') }}
45-
restore-keys: poetry-
46-
47-
- name: Install dependencies # if cache has changed
48-
if: steps.cache-deps.cache-hit != 'true'
34+
- name: Build the libecalc package (wheel and sdist by default)
4935
run: |
50-
poetry config virtualenvs.in-project true
51-
poetry install --no-interaction
36+
poetry build
5237
5338
- name: Publish to PyPI
54-
env:
55-
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
56-
run: |
57-
poetry config pypi-token.pypi $PYPI_TOKEN
58-
poetry publish --build
39+
uses: pypa/gh-action-pypi-publish@release/v1
40+
with:
41+
# repository-url: https://test.pypi.org/legacy/ # NOTE: Only needed to specify for Test PyPI
42+
packages-dir: dist/

.github/workflows/release-please.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,4 @@ jobs:
2525
id-token: write
2626
needs: release-please
2727
uses: equinor/ecalc/.github/workflows/publish.yml@main
28-
secrets:
29-
pypi_token: ${{ secrets.PYPI_TOKEN }}
3028
if: ${{ needs.release-please.outputs.release_created }}

0 commit comments

Comments
 (0)