Skip to content

Commit

Permalink
Chore: Swap back to static versioning for this release (#510)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Watkins <[email protected]>
Signed-off-by: Modeseven Industrial Solutions <[email protected]>
  • Loading branch information
ModeSevenIndustrialSolutions authored Jul 19, 2024
1 parent 39acc7b commit 1be2d51
Show file tree
Hide file tree
Showing 4 changed files with 282 additions and 276 deletions.
223 changes: 223 additions & 0 deletions .github/workflows/new-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
---
name: "📦 Release and Publish"

# GitHub/PyPI trusted publisher documentation:
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/

# yamllint disable-line rule:truthy
on:
workflow_dispatch:
#pull_request:
# branches: [ main, master ]
# types: [closed]
#push:
# branches: [ main, master ]
# tags:
# - 'v*.*.*'

env:
python-version: "3.10"
package-path: "dist"

### BUILD ###

jobs:

build:
name: "🐍 Build Project"
if:
github.event.pull_request.merged == true ||
github.event_name == 'push' ||
github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: write
# id-token: write
outputs:
publish: ${{ steps.build.outputs.publish }}

steps:
### BUILDING ###

- name: "Checkout repository"
uses: actions/checkout@v4

- name: "Setup Python"
uses: actions/setup-python@v5
with:
python-version: ${{ env.python-version }}

- name: "Setup PDM for build commands"
uses: pdm-project/setup-pdm@v4
with:
python-version: ${{ env.python-version }}

- name: "Fetch current semantic tag"
id: fetch-tags
# yamllint disable-line rule:line-length
uses: os-climate/devops-reusable-workflows/.github/actions/latest-semantic-tag@main

- name: "🏷️ Create initial tag"
id: set-initial-tag
if: steps.fetch-tags.outputs.missing == 'true'
# https://github.com/softprops/action-gh-release
uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
prerelease: true
tag_name: v0.0.1

- name: "Build with PDM backend"
id: build
# if: steps.fetch-tags.outputs.missing == 'false'
run: |
echo "Current semantic tag: ${{ steps.fetch-tags.outputs.tag }}"
echo "Github versioning: ${{ github.ref_name }}"
pdm build
if ! (ls ${{ env.package-path }}/*.dev*.*); then
echo "publish=true" >> "$GITHUB_OUTPUT"
fi
### SIGNING ###

- name: "Sign packages with Sigstore"
uses: sigstore/[email protected]
env:
package-path: ${{ env.package-path }}
with:
inputs: >-
./${{ env.package-path }}/*.tar.gz
./${{ env.package-path }}/*.whl
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: ${{ github.ref_name }}
path: ${{ env.package-path }}

### PUBLISH GITHUB ###

github:
name: "📦 Publish to GitHub"
# Only publish on tag pushes
needs: build
runs-on: ubuntu-latest
permissions:
# IMPORTANT: mandatory to publish artefacts
contents: write
steps:
- name: "⬇ Download build artefacts"
uses: actions/download-artifact@v4
with:
name: ${{ github.ref_name }}
path: ${{ env.package-path }}

- name: "🌥️ Set environment variables"
id: setenv
run: |
# vernum="${{ env.python-version }}.$(date +'%Y%m%d%H%M')"
datetime="$(date +'%Y%m%d%H%M')"
echo "datetime=${datetime}" >> "$GITHUB_OUTPUT"
- name: "📦 Publish DEVELOPMENT artefacts to GitHub"
if: startsWith(github.ref, 'refs/tags/') != true
# https://github.com/softprops/action-gh-release
uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
prerelease: true
tag_name: ${{ github.ref_name }}-dev
name: "Test/Development Build: ${{ github.ref_name }}"
# body_path: ${{ github.workspace }}/CHANGELOG.rst
files: |
${{ env.package-path }}/*.tar.gz
${{ env.package-path }}/*.whl
${{ env.package-path }}/*.sigstore*
- name: "📦 Publish PRODUCTION artefacts to GitHub"
if: startsWith(github.ref, 'refs/tags/')
# https://github.com/softprops/action-gh-release
uses: softprops/action-gh-release@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
prerelease: false
tag_name: ${{ github.ref_name }}
name: "Test/Development Build: ${{ github.ref_name }}"
# body_path: ${{ github.workspace }}/CHANGELOG.rst
files: |
${{ env.package-path }}/*.tar.gz
${{ env.package-path }}/*.whl
${{ env.package-path }}/*.sigstore*
### PUBLISH PYPI TEST ###

testpypi:
name: "📦 Test PyPI publishing"
# Only publish on tag pushes
# if: startsWith(github.ref, 'refs/tags/')
needs: build
runs-on: ubuntu-latest
environment:
name: testpypi
permissions:
# IMPORTANT: mandatory for trusted publishing
id-token: write
steps:
- name: "⬇ Download build artefacts"
uses: actions/download-artifact@v4
with:
name: ${{ github.ref_name }}
path: ${{ env.package-path }}

- name: "Validate build artefacts"
id: files
run: |
if [ -f ${{ env.package-path }}/buildvars.txt ]; then
rm ${{ env.package-path }}/buildvars.txt
fi
if (ls ${{ env.package-path }}/*.sigstore*); then
rm ${{ env.package-path }}/*.sigstore*
fi
- name: "Publish to test PyPI"
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
verbose: true
packages-dir: ${{ env.package-path }}


### PUBLISH PYPI ###

pypi:
name: "📦 Publish to PyPI"
# Only publish on tag pushes
if:
startsWith(github.ref, 'refs/tags/') &&
needs.build.outputs.publish == 'true'
# contains(github.event.head_commit.message, '[release]')
needs: [ build, testpypi ]
runs-on: ubuntu-latest
environment:
name: pypi
permissions:
# IMPORTANT: mandatory for trusted publishing
id-token: write
steps:
- name: "⬇ Download build artefacts"
uses: actions/download-artifact@v4
with:
name: ${{ github.ref_name }}
path: ${{ env.package-path }}

- name: "Remove files unsupported by PyPi"
run: |
if (ls ${{ env.package-path }}/*.sigstore*); then
rm ${{ env.package-path }}/*.sigstore*
fi
# - name: "📦 Publish to PyPI"
# uses: pypa/gh-action-pypi-publish@release/v1
# with:
# verbose: true
# packages-dir: ${{ env.package-path }}
Loading

0 comments on commit 1be2d51

Please sign in to comment.