generated from thclark/django-rabid-armadillo
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MRG: Merge pull request #70 from octue/use-pypi-trusted-publisher
Use trusted publisher to publish to PyPI in `cd` workflow
- Loading branch information
Showing
4 changed files
with
164 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
name: cd | ||
description: This workflow releases a new version of the package before publishing it to PyPI. | ||
|
||
on: | ||
pull_request: | ||
|
@@ -7,53 +8,50 @@ on: | |
- main | ||
|
||
jobs: | ||
publish: | ||
# This job will only run if the PR has been merged (and not closed without merging). | ||
if: "github.event.pull_request.merged == true && !contains(github.event.pull_request.head.message, 'skipci')" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Test package is publishable with PyPI test server | ||
uses: JRubics/[email protected] | ||
with: | ||
python_version: '3.9' | ||
pypi_token: ${{ secrets.TEST_PYPI_TOKEN }} | ||
repository_name: 'testpypi' | ||
repository_url: 'https://test.pypi.org/legacy/' | ||
|
||
- name: Publish latest package to PyPI | ||
uses: JRubics/[email protected] | ||
with: | ||
python_version: '3.9' | ||
poetry_version: '==1.4.2' # (PIP version specifier syntax) | ||
pypi_token: ${{ secrets.PYPI_TOKEN }} | ||
ignore_dev_requirements: 'yes' | ||
|
||
release: | ||
# This job will only run if the PR has been merged (and not closed without merging). | ||
if: "github.event.pull_request.merged == true && !contains(github.event.pull_request.head.message, 'skipci')" | ||
if: "${{ github.event.pull_request.merged == true }}" | ||
runs-on: ubuntu-latest | ||
needs: [publish] | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install poetry | ||
run: pip install poetry | ||
uses: snok/[email protected] | ||
|
||
- name: Check pyproject.toml file | ||
run: poetry check | ||
|
||
- name: Get package version | ||
id: version | ||
run: echo "::set-output name=package_version::$(poetry version -s)" | ||
id: get-package-version | ||
run: echo "package_version=$(poetry version -s)" >> $GITHUB_OUTPUT | ||
|
||
- name: Create release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, no need to create your own. | ||
with: | ||
tag_name: ${{ steps.version.outputs.package_version }} | ||
tag_name: ${{ steps.get-package-version.outputs.package_version }} | ||
release_name: ${{ github.event.pull_request.title }} | ||
body: ${{ github.event.pull_request.body }} | ||
draft: false | ||
prerelease: false | ||
|
||
publish: | ||
needs: release | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write | ||
contents: read | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install poetry | ||
uses: snok/[email protected] | ||
|
||
- name: Build a binary wheel and a source tarball | ||
run: poetry build | ||
|
||
- name: Publish package distributions to PyPI | ||
uses: pypa/[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,11 @@ on: | |
- main | ||
|
||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
types: | ||
- opened | ||
- reopened | ||
- synchronize | ||
- ready_for_review | ||
branches: | ||
- main | ||
|
||
|
@@ -19,8 +23,15 @@ on: | |
default: false | ||
|
||
jobs: | ||
check-semantic-version: | ||
if: github.event.pull_request.draft == false | ||
uses: octue/workflows/.github/workflows/check-semantic-version.yml@main | ||
with: | ||
path: pyproject.toml | ||
breaking_change_indicated_by: minor | ||
|
||
run-tests: | ||
if: "!contains(github.event.head_commit.message, 'skipci')" | ||
if: github.event.pull_request.draft == false | ||
strategy: | ||
fail-fast: true | ||
matrix: | ||
|
@@ -45,17 +56,17 @@ jobs: | |
--health-retries 5 | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Python ${{ matrix.python }} | ||
uses: actions/setup-python@v3 | ||
- name: Setup python ${{ matrix.python }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python }} | ||
|
||
# See the repo of this action for way more advanced caching strategies than used here | ||
- name: Install Poetry | ||
uses: snok/install-poetry@v1 | ||
- name: Install poetry | ||
uses: snok/install-poetry@v1.4.1 | ||
|
||
# For more advanced configuration see https://github.com/ymyzk/tox-gh-actions | ||
- name: Install tox and plugins | ||
|
@@ -81,3 +92,26 @@ jobs: | |
# Token is not required for public repos, but see: | ||
# https://community.codecov.com/t/upload-issues-unable-to-locate-build-via-github-actions-api/3954 | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
|
||
test-publish: | ||
runs-on: ubuntu-latest | ||
needs: run-tests | ||
permissions: | ||
id-token: write | ||
contents: read | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install poetry | ||
uses: snok/[email protected] | ||
|
||
- name: Build a binary wheel and a source tarball | ||
run: poetry build | ||
|
||
- name: Test package is publishable with PyPI test server | ||
uses: pypa/[email protected] | ||
with: | ||
repository-url: https://test.pypi.org/legacy/ | ||
skip-existing: true | ||
verbose: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# For most projects, this workflow file will not need changing; you simply need | ||
# to commit it to your repository. | ||
# | ||
# You may wish to alter this file to override the set of languages analyzed, | ||
# or to provide custom queries or build logic. | ||
# | ||
# ******** NOTE ******** | ||
# We have attempted to detect the languages in your repository. Please check | ||
# the `language` matrix defined below to confirm you have the correct set of | ||
# supported CodeQL languages. | ||
# | ||
name: "CodeQL Advanced" | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
analyze: | ||
name: Analyze (${{ matrix.language }}) | ||
# Runner size impacts CodeQL analysis time. To learn more, please see: | ||
# - https://gh.io/recommended-hardware-resources-for-running-codeql | ||
# - https://gh.io/supported-runners-and-hardware-resources | ||
# - https://gh.io/using-larger-runners (GitHub.com only) | ||
# Consider using larger runners or machines with greater resources for possible analysis time improvements. | ||
runs-on: ubuntu-latest | ||
permissions: | ||
# required for all workflows | ||
security-events: write | ||
|
||
# required to fetch internal or private CodeQL packs | ||
packages: read | ||
|
||
# only required for workflows in private repositories | ||
actions: read | ||
contents: read | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- language: javascript-typescript | ||
build-mode: none | ||
- language: python | ||
build-mode: none | ||
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' | ||
# Use `c-cpp` to analyze code written in C, C++ or both | ||
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both | ||
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both | ||
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis, | ||
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning. | ||
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how | ||
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
# Initializes the CodeQL tools for scanning. | ||
- name: Initialize CodeQL | ||
uses: github/codeql-action/init@v3 | ||
with: | ||
languages: ${{ matrix.language }} | ||
build-mode: ${{ matrix.build-mode }} | ||
# If you wish to specify custom queries, you can do so here or in a config file. | ||
# By default, queries listed here will override any specified in a config file. | ||
# Prefix the list here with "+" to use these queries and those in the config file. | ||
|
||
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs | ||
# queries: security-extended,security-and-quality | ||
|
||
# If the analyze step fails for one of the languages you are analyzing with | ||
# "We were unable to automatically build your code", modify the matrix above | ||
# to set the build mode to "manual" for that language. Then modify this step | ||
# to build your code. | ||
# ℹ️ Command-line programs to run using the OS shell. | ||
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun | ||
- if: matrix.build-mode == 'manual' | ||
shell: bash | ||
run: | | ||
echo 'If you are using a "manual" build mode for one or more of the' \ | ||
'languages you are analyzing, replace this with the commands to build' \ | ||
'your code, for example:' | ||
echo ' make bootstrap' | ||
echo ' make release' | ||
exit 1 | ||
- name: Perform CodeQL Analysis | ||
uses: github/codeql-action/analyze@v3 | ||
with: | ||
category: "/language:${{matrix.language}}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters