Skip to content

Release

Release #72

Workflow file for this run

name: Release
on:
workflow_run:
workflows: ["Run Tests"]
types:
- completed
jobs:
auto-merge:
runs-on: ubuntu-latest
outputs:
mergeResult: ${{ steps.merge.outputs.mergeResult }}
prLabels: ${{ steps.get_labels.outputs.labels }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get PR labels
id: get_labels
uses: actions/github-script@v6
with:
script: |
const prs = context.payload.workflow_run.pull_requests;
if (!prs || prs.length === 0) {
core.info("Could not find any pull requests in the workflow run.");
core.setOutput("labels", "[]");
return;
}
const prNumber = prs[0].number;
core.info(`Found PR number: ${prNumber}`);
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
const labels = pr.labels.map(label => label.name);
core.info(`Retrieved labels: ${labels}`);
core.setOutput("labels", JSON.stringify(labels));
- name: Debug labels output
run: |
echo "Labels output: ${{ steps.get_labels.outputs.labels }}"
- name: Auto merge if auto-merge-ok label exists
id: merge
if: contains(fromJson(steps.get_labels.outputs.labels), 'auto-merge-ok')
uses: pascalgn/automerge-action@v0.16.3
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
MERGE_LABELS: "auto-merge-ok"
MERGE_METHOD: squash
MERGE_DELETE_BRANCH: true
tag-release:
runs-on: ubuntu-latest
needs: auto-merge
if: ${{ needs.auto-merge.outputs.mergeResult == 'merged' && contains(fromJson(needs.auto-merge.outputs.prLabels || '[]'), 'release') }}
steps:
- uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
submodules: true
token: ${{ secrets.GITHUB_TOKEN }}
- name: Debug outputs from auto-merge
run: |
echo "Merge Result: ${{ needs.auto-merge.outputs.mergeResult }}"
echo "PR Labels: ${{ needs.auto-merge.outputs.prLabels }}"
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install package
run: |
python -m pip install --upgrade pip setuptools wheel
pip install .[all]
- name: Get version from package
id: get_version
run: |
VERSION=$(python -c "import pysdfgen; print(pysdfgen.__version__)")
echo "Detected version: $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Tag and push release
run: |
git tag "v${{ steps.get_version.outputs.version }}"
git push origin "v${{ steps.get_version.outputs.version }}"
build_sdist:
runs-on: ubuntu-latest
needs: auto-merge
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: main
submodules: true
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install build tool
run: python -m pip install build
- name: Build source distribution
run: python -m build --sdist
- name: Upload sdist artifact
uses: actions/upload-artifact@v4
with:
name: sdist-artifact
path: dist/*.tar.gz
build_wheels:
name: Build wheels on ${{ matrix.os }}
needs: auto-merge
runs-on: ${{ matrix.os }}
strategy:
matrix:
# https://github.com/actions/runner-images
# Note: To test macOS-x with Intel architecture,
# you need to use the paid macOS-x-large runner, as macOS-x is grouped with ARM-based runners.
# https://docs.github.com/en/actions/concepts/runners/about-larger-runners
os: [ubuntu-latest, ubuntu-24.04-arm, windows-latest, macos-13, macos-latest]
steps:
- uses: actions/checkout@v4
with:
ref: main
submodules: true
# Used to host cibuildwheel
- uses: actions/setup-python@v5
- name: Install cibuildwheel
run: python -m pip install cibuildwheel==2.16.2
- name: Build wheels
run: python -m cibuildwheel --output-dir wheelhouse
- uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
path: ./wheelhouse/*.whl
upload_pypi:
needs: [build_wheels, build_sdist, tag-release]
runs-on: ubuntu-latest
environment: pypi
steps:
- uses: actions/setup-python@v4
with:
python-version: "3.12"
- uses: actions/download-artifact@v4
with:
# unpacks all CIBW artifacts into dist/
path: dist
pattern: cibw-wheels-*
merge-multiple: true
- name: Download sdist artifact
uses: actions/download-artifact@v4
with:
name: sdist-artifact
path: dist
- uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_TOKEN }}