Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 64 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
name: Release SDK if needed

# Publishes onepasswordconnectsdk to PyPI with the PYPI_API_TOKEN secret while it is set, and
# with PyPI trusted publishing (OIDC) once it is deleted. The trusted publisher is bound to
# this file (release.yml) and the `pypi` environment; renaming either breaks publishing.
#
# Runs when a release/* PR is merged into main. The publish job waits for approval on the
# `pypi` environment before anything is uploaded.

on:
pull_request:
branches: main
types: closed

permissions:
contents: write
contents: read

jobs:
release:
build:
name: Build
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true && contains(github.event.pull_request.head.ref, 'release/')
permissions:
contents: read
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
Expand All @@ -22,6 +32,7 @@ jobs:
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Setup Python
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
with:
Expand All @@ -33,17 +44,66 @@ jobs:
poetry install
- name: Build the package
run: poetry build
- name: Publish to PyPi
- name: Upload distributions
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: dist
path: dist/
if-no-files-found: error

# Only this job gets an OIDC token, and it runs nothing from the repo: it uploads the
# files the build job made.
publish:
name: Publish to PyPI
needs: build
runs-on: ubuntu-latest
# Must match the environment on the PyPI trusted publisher config.
environment:
name: pypi
url: https://pypi.org/project/onepasswordconnectsdk/
permissions:
id-token: write # PyPI trusted publishing (OIDC)
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit

- name: Download distributions
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: dist
path: dist/

# While the PYPI_API_TOKEN secret is set, the action uploads with it. Once the secret is
# deleted, the password is empty, so the action exchanges the job's OIDC token for a
# short-lived PyPI token and attaches PEP 740 attestations to the uploaded files.
- name: Publish to PyPI
uses: step-security/gh-action-pypi-publish@eccc9148d1fa355476d98c01819ec34b75a86f24 # v1.14.2
with:
password: ${{ secrets.PYPI_API_TOKEN }}

# Kept in its own job so only this job can write to the repo, and the publish job
# (which holds the PyPI OIDC token) stays read-only.
release:
name: GitHub release
needs: publish
runs-on: ubuntu-latest
permissions:
contents: write # create the tag and GitHub release
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit

- name: Create Release tag
id: create-tag
env:
PR_REF: ${{ github.event.pull_request.head.ref }}
run: |
release_tag=$(echo "$PR_REF" | cut -d "/" -f2)
echo "::set-output name=release-tag::$release_tag"
echo "release-tag=$release_tag" >> "$GITHUB_OUTPUT"
- name: Make new release
uses: step-security/release-action@a0d8e0f90f554c15366ca2c9046bf4090d24adbe # v1.21.0
with:
Expand Down