Skip to content

Commit

Permalink
ci: ci test release
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymon Szyszkowski committed Aug 13, 2024
1 parent bac9b9d commit 8c98b46
Show file tree
Hide file tree
Showing 5 changed files with 279 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
- name: Install the latest version of rye
run: make dev
- name: Run checks
- uses: pre-commit/action@v3.0.1
uses: pre-commit/action@v3.0.1
39 changes: 39 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Release

on:
push:
tags:
- "v*"

env:
PYTHON_VERSION_DEFAULT: "3.10.8"

jobs:
release:
runs-on: ubuntu-latest
environment: PyPI
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
contents: write
steps:
- uses: actions/create-github-app-token@v1
id: trigger-token
with:
app-id: ${{ vars.TRIGGER_WORKFLOW_GH_APP_ID}}
private-key: ${{ secrets.TRIGGER_WORKFLOW_GH_APP_KEY }}
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.10.8
- name: Install the latest version of rye
run: make dev
- name: Build package
run: make build
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
packages-dir: dist/
34 changes: 34 additions & 0 deletions .github/workflows/release_pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: PR to trigger release

"on":
schedule:
- cron: "15 16 * * 4"

jobs:
pull-request:
runs-on: ubuntu-latest
environment: PyPI
steps:
- uses: actions/create-github-app-token@v1
id: trigger-token
with:
app-id: ${{ vars.TRIGGER_WORKFLOW_GH_APP_ID}}
private-key: ${{ secrets.TRIGGER_WORKFLOW_GH_APP_KEY }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
repository: opentargets/gentropy
token: ${{ secrets.GITHUB_TOKEN }}
persist-credentials: false
- uses: actions/checkout@v3
- name: pull-request
uses: diillson/auto-pull-request@v1.0.1
with:
source_branch: "dev"
destination_branch: "main"
pr_title: "chore: trigger release process"
pr_body: ":warning: *This PR requires a MERGE COMMIT (Don't squash or rebase!)*"
pr_label: "auto-pr"
pr_draft: false
pr_allow_empty: true
github_token: ${{ secrets.GITHUB_TOKEN }}
139 changes: 139 additions & 0 deletions .github/workflows/tag.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
name: Release

"on":
push:
branches: ["main"]

concurrency:
group: deploy
cancel-in-progress: false # prevent hickups with semantic-release

env:
PYTHON_VERSION_DEFAULT: "3.10.8"

jobs:
release:
runs-on: ubuntu-latest
concurrency: release
environment: PyPI
permissions:
contents: write

steps:
# NOTE: commits using GITHUB_TOKEN does not trigger workflows
- uses: actions/create-github-app-token@v1
id: trigger-token
with:
app-id: ${{ vars.TRIGGER_WORKFLOW_GH_APP_ID}}
private-key: ${{ secrets.TRIGGER_WORKFLOW_GH_APP_KEY }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
repository: opentargets/gentropy
token: ${{ secrets.GITHUB_TOKEN }}
persist-credentials: false

- name: Python Semantic Release
id: semrelease
# v9.6.0 is required due to the python v3.12 in the newer version of semantic release action which
# breaks the poetry build command.
uses: python-semantic-release/python-semantic-release@v9.6.0
with:
github_token: ${{ steps.trigger-token.outputs.token }}

- name: Publish package to GitHub Release
uses: python-semantic-release/upload-to-gh-release@main
if: ${{ steps.semrelease.outputs.released }} == 'true'
with:
# NOTE: allow to start the workflow when push action on tag gets executed
# requires using GH_APP to authenitcate, otherwise push authorised with
# the GITHUB_TOKEN does not trigger the tag artifact workflow.
# see https://github.com/actions/create-github-app-token
github_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ steps.semrelease.outputs.tag }}

- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
needs: release
name: >-
Publish 📦 in PyPI
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/gentropy
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

publish-to-testpypi:
name: Publish 📦 in TestPyPI
needs: release
if: github.ref != 'refs/heads/main'
runs-on: ubuntu-latest

environment:
name: testpypi
url: https://test.pypi.org/p/gentropy

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/

documentation:
needs: release
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION_DEFAULT }}
- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: |
venv-${{ runner.os }}-\
${{ env.PYTHON_VERSION_DEFAULT }}-\
${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
- name: Install library
run: poetry install --without tests --no-interaction
- name: Publish docs
run: poetry run mkdocs gh-deploy --force
67 changes: 66 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "gentroutils"
version = "0.1.0"
version = "0.0.0"
description = "Add your description here"
authors = [
{ name = "Szymon Szyszkowski", email = "ss60@mib117351s.internal.sanger.ac.uk" },
Expand Down Expand Up @@ -126,3 +126,68 @@ warn_unused_ignores = true
[[tool.mypy.overrides]]
module = ["google.cloud", "pyfiglet", "click", "google.cloud.storage"]
ignore_missing_imports = true


[tool.semantic_release]
version_toml = ["pyproject.tolm:project.version"]
assets = []
commit_message = "{version}\n\nAutomatically generated by python-semantic-release"
commit_parser = "angular"
logging_use_named_masks = false
major_on_zero = true
allow_zero_version = true
tag_format = "v{version}"

[tool.semantic_release.branches.main]
match = "(main|master)"
prerelease_token = "rc"
prerelease = false

[semantic_release.changelog]
template_dir = "templates"
changelog_file = "CHANGELOG.md"
exclude_commit_patterns = []

[tool.semantic_release.changelog.environment]
block_start_string = "{%"
block_end_string = "%}"
variable_start_string = "{{"
variable_end_string = "}}"
comment_start_string = "{#"
comment_end_string = "#}"
trim_blocks = false
lstrip_blocks = false
newline_sequence = "\n"
keep_trailing_newline = false
extensions = []
autoescape = true

[tool.semantic_release.commit_author]
env = "GIT_COMMIT_AUTHOR"
default = "semantic-release <semantic-release>"

[tool.semantic_release.commit_parser_options]
allowed_tags = [
"build",
"chore",
"ci",
"docs",
"feat",
"fix",
"perf",
"style",
"refactor",
"test",
]
minor_tags = ["feat"]
patch_tags = ["fix", "perf", "docs", "style", "test", "ci"]
default_bump_level = 0

[tool.semantic_release.remote]
name = "origin"
type = "github"
ignore_token_for_push = false

[tool.semantic_release.publish]
dist_glob_patterns = ["dist/*"]
upload_to_vcs_release = true

0 comments on commit 8c98b46

Please sign in to comment.