Skip to content

Commit

Permalink
ci: 🎡 use semantic-release (node) [release:patch]
Browse files Browse the repository at this point in the history
  • Loading branch information
darvid committed Mar 8, 2024
1 parent 725a373 commit 4325e8e
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 403 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Release
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build:
uses: ./.github/workflows/wheels.yml

release:
name: Publish package
runs-on: ubuntu-22.04
concurrency: release
if: github.repository == 'darvid/python-hyperscan'
permissions:
id-token: write
pull-requests: write
contents: write
env:
RELEASE_PR_BRANCH: create-pull-request/patch
steps:
- name: Checkout python-hyperscan
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0

- uses: chainguard-dev/actions/setup-gitsign@main

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Download artifacts
uses: actions/download-artifact@v4
if: github.event_name == 'workflow_dispatch'

- name: Prepare dist
if: github.event_name == 'workflow_dispatch'
run: |
mkdir dist
mv --backup=numbered ./wheel-*/*.whl -t dist/
mv --backup=numbered ./sdist/*.tar.gz -t dist/
ls -ahl dist/
rm -rf dist/*~
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.12

- name: Release
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: npx semantic-release
85 changes: 4 additions & 81 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ name: Build
on:
push:
branches:
- main
- "**"
- "!main"
workflow_call:
workflow_dispatch:

concurrency:
Expand All @@ -13,6 +15,7 @@ jobs:
build_environment:
name: ${{ matrix.os }} build environment
runs-on: ${{ matrix.os }}
if: github.repository == 'darvid/python-hyperscan'
env:
PCRE_VERSION: "8.45"

Expand Down Expand Up @@ -345,83 +348,3 @@ jobs:
name: sdist
path: |
dist/*.tar.gz
release:
name: Publish package
runs-on: ubuntu-22.04
concurrency: release
if: github.repository == 'darvid/python-hyperscan'
needs: [build_wheels, build_sdist]
permissions:
id-token: write
pull-requests: write
contents: write
env:
RELEASE_PR_BRANCH: create-pull-request/patch
steps:
- name: Checkout python-hyperscan
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0

- uses: chainguard-dev/actions/setup-gitsign@main

- name: Check if release needed
id: release
uses: python-semantic-release/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
root_options: "-vv --noop"
# python-semantic-release displays what it would have
# committed if commit is true and noop is set
commit: "true"

- name: Download artifacts
uses: actions/download-artifact@v4
if: github.event_name == 'workflow_dispatch' || steps.release.outputs.released == 'true'

- name: Prepare dist
if: github.event_name == 'workflow_dispatch' || steps.release.outputs.released == 'true'
run: |
mkdir dist
mv --backup=numbered ./wheel-*/*.whl -t dist/
mv --backup=numbered ./sdist/*.tar.gz -t dist/
ls -ahl dist/
rm -rf dist/*~
- name: Create release branch
if: steps.release.outputs.released == 'true'
run: |
# use the same default branch name that create-pull-request uses
git checkout -b ${RELEASE_PR_BRANCH}
git branch --set-upstream-to=${RELEASE_PR_BRANCH}
- name: Semantic release
uses: python-semantic-release/[email protected]
if: steps.release.outputs.released == 'true'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
root_options: "-vv"

- name: Create PR
uses: peter-evans/[email protected]
if: steps.release.outputs.released == 'true'
with:
base: main
assignees: ${{ github.repository_owner }}
title: "Release ${{ steps.release.outputs.version }}"

- name: Publish package distributions to GitHub Releases
if: github.event_name == 'workflow_dispatch' || steps.release.outputs.released == 'true'
uses: python-semantic-release/upload-to-gh-release@main
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ steps.release.outputs.tag }}

- name: Publish package distributions to PyPI
if: github.event_name == 'workflow_dispatch' || steps.release.outputs.released == 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
verbose: true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
pnpm-lock.yaml
node_modules/

.envrc

*.whl
Expand Down
38 changes: 38 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"branches": [
"main",
"next"
],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"preset": "conventionalcommits",
"releaseRules": [
{
"message": "*[release:minor]*",
"release": "minor"
},
{
"message": "*[release:patch]*",
"release": "patch"
}
]
}
],
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/github",
"semantic-release-pypi",
[
"@semantic-release/git",
{
"assets": [
"pyproject.toml",
"src/hyperscan/_version.py"
],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}
]
]
}
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"devDependencies": {
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^9.2.6",
"conventional-changelog-conventionalcommits": "^7.0.2",
"semantic-release": "^22.0.5",
"semantic-release-pypi": "^3.0.0-beta.2"
}
}
Loading

0 comments on commit 4325e8e

Please sign in to comment.