Skip to content

Commit 31aec62

Browse files
authored
Merge pull request #51 from matthewfeickert/ci/add-trusted-publishers-workflow
CI: Add publishing to PyPI and TestPyPI with trusted publishers
2 parents f047068 + 1f146b6 commit 31aec62

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

.github/dependabot.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 2
2+
updates:
3+
# Maintain dependencies for GitHub Actions
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"
8+
labels:
9+
- "github-actions"
10+
- "dependencies"
11+
reviewers:
12+
- "asmeurer"

.github/workflows/publish-package.yml

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: publish distributions
2+
on:
3+
push:
4+
branches:
5+
- main
6+
tags:
7+
- [0-9]+.[0-9]+
8+
- [0-9]+.[0-9]+.[0-9]+
9+
pull_request:
10+
branches:
11+
- main
12+
release:
13+
types: [published]
14+
workflow_dispatch:
15+
inputs:
16+
publish:
17+
type: choice
18+
description: 'Publish to TestPyPI?'
19+
options:
20+
- false
21+
- true
22+
23+
concurrency:
24+
group: ${{ github.workflow }}-${{ github.ref }}
25+
cancel-in-progress: true
26+
27+
jobs:
28+
build:
29+
name: Build Python distribution
30+
runs-on: ubuntu-latest
31+
32+
steps:
33+
- uses: actions/checkout@v3
34+
with:
35+
fetch-depth: 0
36+
37+
- name: Set up Python
38+
uses: actions/setup-python@v4
39+
with:
40+
python-version: '3.x'
41+
42+
- name: Install python-build and twine
43+
run: |
44+
python -m pip install --upgrade pip setuptools
45+
python -m pip install build twine
46+
python -m pip list
47+
48+
- name: Build a wheel and a sdist
49+
run: |
50+
PYTHONWARNINGS=error,default::DeprecationWarning python -m build .
51+
52+
- name: Verify the distribution
53+
run: twine check --strict dist/*
54+
55+
- name: List contents of sdist
56+
run: python -m tarfile --list dist/array_api_compat-*.tar.gz
57+
58+
- name: List contents of wheel
59+
run: python -m zipfile --list dist/array_api_compat-*.whl
60+
61+
- name: Upload distribution artifact
62+
uses: actions/upload-artifact@v3
63+
with:
64+
name: dist-artifact
65+
path: dist
66+
67+
publish:
68+
name: Publish Python distribution to (Test)PyPI
69+
if: github.event_name != 'pull_request' && github.repository == 'data-apis/array-api-compat'
70+
needs: build
71+
runs-on: ubuntu-latest
72+
# Mandatory for publishing with a trusted publisher
73+
# c.f. https://docs.pypi.org/trusted-publishers/using-a-publisher/
74+
permissions:
75+
id-token: write
76+
# Restrict to the environment set for the trusted publisher
77+
environment:
78+
name: publish-package
79+
80+
steps:
81+
- name: Download distribution artifact
82+
uses: actions/download-artifact@v3
83+
with:
84+
name: dist-artifact
85+
path: dist
86+
87+
- name: List all files
88+
run: ls -lh dist
89+
90+
- name: Publish distribution 📦 to Test PyPI
91+
# Publish to TestPyPI on tag events of if manually triggered
92+
# Compare to 'true' string as booleans get turned into strings in the console
93+
if: >-
94+
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v'))
95+
|| (github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true')
96+
uses: pypa/[email protected]
97+
with:
98+
repository-url: https://test.pypi.org/legacy/
99+
print-hash: true
100+
101+
- name: Publish distribution 📦 to PyPI
102+
if: github.event_name == 'release' && github.event.action == 'published'
103+
uses: pypa/[email protected]
104+
with:
105+
print-hash: true

0 commit comments

Comments
 (0)