Skip to content

Commit 19741ea

Browse files
committed
chore(ci): refactor workflows, enable github releases and define branch policies under .releaserc, publish to pypi via trusted publishing mechanism
1 parent 415d0f8 commit 19741ea

6 files changed

Lines changed: 165 additions & 96 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Refetch artifacts
2+
runs:
3+
using: "composite"
4+
steps:
5+
- uses: actions/download-artifact@v4
6+
with:
7+
name: wheel
8+
path: ./dist
9+
- uses: actions/download-artifact@v4
10+
with:
11+
name: sdist
12+
path: ./dist

.github/actions/setup-semantic-release/action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ runs:
1414
semantic-release \
1515
@semantic-release/exec \
1616
@semantic-release/git \
17+
@semantic-release/github \
1718
@semantic-release/changelog \
1819
@google/semantic-release-replace-plugin
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Lint and test
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- master
7+
- 'ci/**' # ci testing, pre-releases
8+
#- 'feature/**'
9+
10+
jobs:
11+
lint:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v5
15+
- uses: ./.github/actions/setup
16+
- name: Lint
17+
id: lint
18+
run: tox -e lint
19+
continue-on-error: true
20+
- name: Emit warning if lint failed
21+
if: ${{ steps.lint.outcome != 'success' }}
22+
run: echo "::warning::Linter failure suppressed (continue-on-error=true)"
23+
test:
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
os: [ ubuntu-latest ]
28+
python:
29+
- "3.12"
30+
- "3.11"
31+
- "3.10"
32+
- "3.9.14"
33+
- "3.8"
34+
runs-on: ${{ matrix.os }}
35+
steps:
36+
- uses: actions/checkout@v5
37+
- uses: ./.github/actions/setup
38+
with:
39+
python: ${{ matrix.python }}
40+
- name: Test
41+
run: tox

.github/workflows/main.yml

Lines changed: 0 additions & 95 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Release
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Lint and test"]
6+
types:
7+
- completed
8+
branches:
9+
- master
10+
- 'ci/**' # ci testing, pre-releases
11+
#- develop # can emit -dev releases but we do not want to
12+
workflow_dispatch:
13+
inputs:
14+
dry_run:
15+
description: "Run in dry-run mode (no publish)"
16+
required: false
17+
default: "true"
18+
19+
# MUSTHAVE: Trusted publisher access for both repos.
20+
# NOTE: according to docs, 'test' repo accounts are ephemeral and can be wiped at any time
21+
env:
22+
DRY_RUN: ${{ github.event.inputs.dry_run || 'false' }}
23+
pypi_main_repo: https://upload.pypi.org/legacy/
24+
pypi_test_repo: https://test.pypi.org/legacy/
25+
26+
jobs:
27+
28+
release:
29+
runs-on: ubuntu-latest
30+
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' && (github.event.workflow_run.head_branch == 'master' || startsWith(github.event.workflow_run.head_branch, 'ci/') ) )
31+
permissions:
32+
contents: write
33+
issues: write
34+
pull-requests: write
35+
steps:
36+
- uses: actions/checkout@v5
37+
- uses: ./.github/actions/setup-semantic-release # node+semantic-release
38+
- uses: ./.github/actions/setup # poetry
39+
- id: semantic-release # branch policies defined in .releaserc
40+
env:
41+
GIT_AUTHOR_NAME: appland-release
42+
GIT_AUTHOR_EMAIL: release@app.land
43+
GIT_COMMITTER_NAME: appland-release
44+
GIT_COMMITTER_EMAIL: release@app.land
45+
run: |
46+
if [ "$DRY_RUN" = "true" ]; then
47+
semantic-release --dry-run
48+
else
49+
semantic-release
50+
fi
51+
- name: Upload wheel
52+
if: env.DRY_RUN != "true"
53+
uses: actions/upload-artifact@v4
54+
with:
55+
name: wheel
56+
path: dist/*.whl
57+
- name: Upload sdist
58+
if: env.DRY_RUN != "true"
59+
uses: actions/upload-artifact@v4
60+
with:
61+
name: sdist
62+
path: dist/*.tar.gz
63+
outputs: # not reused in fact
64+
release_tag: ${{ steps.semantic-release.outputs.next_release_tag }}
65+
66+
smoketest:
67+
runs-on: ubuntu-latest
68+
needs: release
69+
if: env.DRY_RUN!="true"
70+
steps:
71+
- uses: actions/checkout@v5
72+
- uses: ./.github/actions/refetch-artifacts
73+
- name: dockerhub login (for seamless docker pulling)
74+
uses: ./.github/actions/dockerhub-login
75+
env:
76+
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
77+
DOCKERHUB_USERNAME: ${{ vars.DOCKERHUB_USERNAME }}
78+
continue-on-error: true
79+
- run: ci/run_tests.sh
80+
env:
81+
SMOKETEST_DOCKER_IMAGE: python:3.12-alpine
82+
83+
pypi:
84+
name: upload release to PyPI
85+
needs: ['release','smoketest']
86+
if: (( env.DRY_RUN != "true" ) && ((github.ref_name == 'master') || startsWith(github.ref_name,"ci/")))
87+
runs-on: ubuntu-latest
88+
environment: pypi
89+
permissions:
90+
id-token: write
91+
steps:
92+
- uses: actions/checkout@v5
93+
- uses: ./.github/actions/refetch-artifacts
94+
- name: Publish package distributions to PyPI
95+
uses: pypa/gh-action-pypi-publish@release/v1
96+
with:
97+
repository-url: ${{ github.ref_name == 'master' && env.pypi_main_repo || env.pypi_test_repo }}

.releaserc.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
branches:
2+
- main
3+
- name: develop
4+
prerelease: dev
5+
- name: ci
6+
prerelease: ci
7+
- name: feature/*
8+
prerelease: rc
19
plugins:
210
- '@semantic-release/commit-analyzer'
311
- '@semantic-release/release-notes-generator'
@@ -18,4 +26,9 @@ plugins:
1826
- CHANGELOG.md
1927
- pyproject.toml
2028
- - '@semantic-release/exec'
21-
- publishCmd: "poetry publish --build -r <%= process.env.PYPI_PUBLISH_REPO ? process.env.PYPI_PUBLISH_REPO : 'pypi' %>"
29+
- prepareCmd: poetry build
30+
- - '@semantic-release/github'
31+
- assets:
32+
- dist/*.whl
33+
- dist/*.tar.gz
34+
branches: master

0 commit comments

Comments
 (0)