Skip to content

Commit 1e02874

Browse files
committed
add separate publish workflow
1 parent 6b50ebf commit 1e02874

1 file changed

Lines changed: 102 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Publish
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
publish_to_pypi:
7+
description: "Publish to PyPI"
8+
required: true
9+
default: "false"
10+
type: choice
11+
options:
12+
- "false"
13+
- "true"
14+
15+
jobs:
16+
# # First check if CI workflow succeeded
17+
# check-ci:
18+
# runs-on: ubuntu-latest
19+
# steps:
20+
# - name: Check CI workflow status
21+
# uses: actions/github-script@v7
22+
# id: check-status
23+
# with:
24+
# script: |
25+
# const ref = context.sha;
26+
# const workflow_name = 'Build and Test';
27+
28+
# const workflow_runs = await github.rest.actions.listWorkflowRuns({
29+
# owner: context.repo.owner,
30+
# repo: context.repo.repo,
31+
# workflow_id: workflow_name,
32+
# head_sha: ref,
33+
# });
34+
35+
# const latest_run = workflow_runs.data.workflow_runs[0];
36+
# if (!latest_run || latest_run.conclusion !== 'success') {
37+
# core.setFailed('CI workflow has not succeeded for this commit');
38+
# return false;
39+
# }
40+
# return true;
41+
42+
publish:
43+
if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }}
44+
# needs: check-ci
45+
runs-on: ubuntu-latest
46+
permissions:
47+
id-token: write
48+
contents: write
49+
attestations: write
50+
steps:
51+
- name: Download all wheel artifacts
52+
uses: actions/download-artifact@v4
53+
with:
54+
workflow: build-and-test.yml
55+
commit: ${{ github.sha }}
56+
path: artifact-download
57+
58+
# Create dist directory
59+
- name: Create dist directory
60+
run: mkdir -p dist
61+
shell: bash
62+
63+
# Move all wheels to dist directory
64+
- name: Collect wheels
65+
run: |
66+
find artifact-download -name "*.whl" -o -name "*.tar.gz" | xargs -I{} cp {} dist/
67+
echo "Package files in dist directory:"
68+
ls -la dist/
69+
shell: bash
70+
71+
- name: Generate artifact attestation
72+
uses: actions/attest-build-provenance@v1
73+
with:
74+
subject-path: "dist/*"
75+
76+
# Publish to TestPyPI
77+
- name: Publish to TestPyPI
78+
uses: PyO3/maturin-action@v1
79+
env:
80+
MATURIN_PYPI_TOKEN: ${{ secrets.TEST_PYPI_API_TOKEN }}
81+
MATURIN_REPOSITORY: testpypi
82+
with:
83+
command: upload
84+
args: --non-interactive --skip-existing dist/*
85+
86+
# Only publish to PyPI if the publish_to_pypi input is true
87+
- name: Publish to PyPI
88+
if: ${{ github.event.inputs.publish_to_pypi == 'true' }}
89+
uses: PyO3/maturin-action@v1
90+
env:
91+
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
92+
with:
93+
command: upload
94+
args: --non-interactive --skip-existing dist/*
95+
96+
# # Create a GitHub release when a tag is created
97+
# - name: Create GitHub Release
98+
# if: ${{ inputs.publish_to_pypi }}
99+
# uses: softprops/action-gh-release@v1
100+
# with:
101+
# generate_release_notes: true
102+
# files: dist/*

0 commit comments

Comments
 (0)