mirror of
https://github.com/arsenetar/send2trash.git
synced 2026-01-22 06:37:18 +00:00
ci: Add ability to use trusted-publishing for PyPI
- Add Publish workflow to run on release tags to upload package to PyPI - Add Build of packages to end of Default CI/CD workflow when on master branch.
This commit is contained in:
22
.github/workflows/default.yml
vendored
22
.github/workflows/default.yml
vendored
@@ -74,3 +74,25 @@ jobs:
|
||||
- name: Run tests
|
||||
run: |
|
||||
pytest
|
||||
build:
|
||||
needs: test
|
||||
runs-on: ubuntu-latest
|
||||
if: github.ref == 'refs/heads/master'
|
||||
steps:
|
||||
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||
- name: Set up Python 3.x
|
||||
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
|
||||
with:
|
||||
python-version: 3.x
|
||||
- name: Install build dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip setuptools build
|
||||
- name: Build package
|
||||
run: |
|
||||
python -m build
|
||||
- name: Upload build artifacts
|
||||
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
|
||||
with:
|
||||
name: dist
|
||||
path: dist/
|
||||
if-no-files-found: error
|
||||
|
||||
32
.github/workflows/publish.yml
vendored
Normal file
32
.github/workflows/publish.yml
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
name: Publish
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '[0-9]+.[0-9]+.[0-9]+'
|
||||
|
||||
jobs:
|
||||
pypi-publish:
|
||||
name: Upload to PyPI
|
||||
runs-on: ubuntu-latest
|
||||
environment: pypi
|
||||
permissions:
|
||||
# IMPORTANT: this permission is mandatory for Trusted Publishing
|
||||
id-token: write
|
||||
steps:
|
||||
- name: Get artifact run
|
||||
id: get_artifact_run
|
||||
run: |
|
||||
RUN_ID=$(gh run list --workflow "Default CI/CD" --branch master --commit "${{ github.sha }}" --status completed --limit 1 --json databaseId --jq ".[].databaseId")
|
||||
if [ -z "$RUN_ID" ]; then
|
||||
echo "No completed workflow run found for commit ${{ github.sha }}"
|
||||
exit 1
|
||||
fi
|
||||
echo "run=$RUN_ID" >> $GITHUB_OUTPUT
|
||||
- name: Fetch build artifacts
|
||||
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
|
||||
with:
|
||||
name: dist
|
||||
run-id: ${{ steps.get_artifact_run.outputs.run }}
|
||||
- name: Publish package distributions to PyPI
|
||||
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
|
||||
Reference in New Issue
Block a user