Create Release #13
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
name: Create Release | |
on: | |
workflow_dispatch: | |
inputs: | |
package-version: | |
description: "Package version" | |
required: false | |
default: "" | |
type: string | |
is_final: | |
description: "It is a final release (not a pre-release)" | |
required: false | |
default: true | |
type: boolean | |
permissions: | |
contents: write # Allow to commit and push. | |
env: | |
DEFAULT_PYTHON_VERSION: "3.12" | |
jobs: | |
#---------------------------------------------- | |
# Prepare | |
prepare: | |
name: Prepare | |
outputs: | |
package-version: ${{ steps.select-package-version.outputs.package-version }} | |
default_python_version: ${{ env.DEFAULT_PYTHON_VERSION }} | |
runs-on: ubuntu-latest | |
steps: | |
#---------------------------------------------- | |
# Display Github environment variables | |
- name: Display Github environment variables | |
run: printenv | grep '^GITHUB_' | sort | |
#---------------------------------------------- | |
# Check-out repo | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
#---------------------------------------------- | |
# Compute the version of the project based in the current checkout branch | |
- name: Compute version | |
id: compute-version | |
uses: ./.github/workflows/compute-version | |
if: ${{ inputs.package-version == '' }} | |
#---------------------------------------------- | |
# Select package version | |
- name: Select package version | |
id: select-package-version | |
run: | | |
if [ -z "${{ inputs.package-version }}" ]; then | |
echo "package-version=${{ steps.compute-version.outputs.pep440-version }}" >> $GITHUB_OUTPUT | |
else | |
echo "package-version=${{ inputs.package-version }}" >> $GITHUB_OUTPUT | |
fi | |
#---------------------------------------------- | |
# Display versions | |
- name: Display versions | |
run: | | |
echo "package-version=${{ steps.select-package-version.outputs.package-version }}" | |
echo "default-python-version=${{ env.DEFAULT_PYTHON_VERSION }}" | |
#---------------------------------------------- | |
# Build and publish the pip package and docker image | |
build: | |
name: Build | |
needs: prepare | |
runs-on: "ubuntu-latest" | |
steps: | |
#---------------------------------------------- | |
# Checkout repo | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-tags: true | |
#---------------------------------------------- | |
# Set the package version | |
- name: Set package version | |
run: echo "PACKAGE_VERSION=${{ needs.prepare.outputs.package-version }}" >> $GITHUB_ENV | |
#---------------------------------------------- | |
# Install envsubst | |
- name: Install envsubst | |
run: sudo apt-get update && sudo apt-get install -y gettext-base | |
#---------------------------------------------- | |
# Bump version in pyproject.toml, config.yaml and build.yaml | |
- name: Bump version | |
run: | | |
envsubst < pyproject.template.toml > pyproject.toml | |
envsubst < addons/gazpar2haws/config.yaml.template > addons/gazpar2haws/config.yaml | |
envsubst < addons/gazpar2haws/build.yaml.template > addons/gazpar2haws/build.yaml | |
#---------------------------------------------- | |
# Commit the changes | |
- name: Commit changes | |
if: true | |
run: | | |
git config --global user.name github-actions | |
git config --global user.email github-actions@github.com | |
git add pyproject.toml addons/gazpar2haws/config.yaml addons/gazpar2haws/build.yaml | |
git commit --allow-empty -m "Bump version to ${PACKAGE_VERSION}" | |
git push | |
#---------------------------------------------- | |
# Tag the commit | |
- name: Git tag | |
if: true | |
uses: ./.github/workflows/git-tag | |
with: | |
tag-name: ${{ needs.prepare.outputs.package-version }} | |
#---------------------------------------------- | |
# Set-up python | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ env.DEFAULT_PYTHON_VERSION }} | |
#---------------------------------------------- | |
# Install & configure poetry ----- | |
- name: Install Poetry | |
uses: snok/install-poetry@v1 | |
with: | |
version: 2.0.0 | |
virtualenvs-create: true | |
virtualenvs-in-project: true | |
virtualenvs-path: .venv | |
#---------------------------------------------- | |
- name: Build package | |
run: poetry build | |
#---------------------------------------------- | |
- name: Upload package | |
uses: actions/upload-artifact@v4 | |
with: | |
name: gazpar2haws | |
path: dist/ | |
#---------------------------------------------- | |
# Publish to PyPI | |
publish-to-pypi: | |
name: Publish to PyPI | |
runs-on: "ubuntu-latest" | |
needs: build | |
if: ${{ startsWith(github.ref, 'refs/heads/main') || startsWith(github.ref, 'refs/heads/develop') || startsWith(github.ref, 'refs/heads/release/') }} | |
environment: | |
name: pypi | |
url: https://pypi.org/p/gazpar2haws | |
permissions: | |
id-token: write # IMPORTANT: mandatory for trusted publishing | |
steps: | |
- name: Download the package | |
uses: actions/download-artifact@v4 | |
with: | |
name: gazpar2haws | |
path: dist/ | |
- name: Publish 📦 to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
verbose: true | |
#---------------------------------------------- | |
# Publish to TestPyPI | |
publish-to-testpypi: | |
name: Publish to TestPyPI | |
runs-on: "ubuntu-latest" | |
needs: build | |
if: ${{ !startsWith(github.ref, 'refs/heads/main') && !startsWith(github.ref, 'refs/heads/develop') && !startsWith(github.ref, 'refs/heads/release/') }} | |
environment: | |
name: testpypi | |
url: https://test.pypi.org/p/gazpar2haws | |
permissions: | |
id-token: write # IMPORTANT: mandatory for trusted publishing | |
steps: | |
- name: Download the package | |
uses: actions/download-artifact@v4 | |
with: | |
name: gazpar2haws | |
path: dist/ | |
- name: Publish 📦 to TestPyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
repository-url: https://test.pypi.org/legacy/ | |
verbose: true | |
#---------------------------------------------- | |
# Publish Docker image to DockerHub | |
publish-to-dockerhub: | |
name: Publish to DockerHub | |
needs: [prepare, build] | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
contents: read | |
attestations: write | |
id-token: write | |
steps: | |
#---------------------------------------------- | |
# Checkout the tag from the repository | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ needs.prepare.outputs.package-version }} | |
#---------------------------------------------- | |
# Publish the Docker image | |
- name: Publish Docker image | |
uses: ./.github/workflows/publish-to-dockerhub | |
with: | |
image: ssenart/gazpar2haws | |
version: ${{ needs.prepare.outputs.package-version }} | |
is_latest : ${{ inputs.is_final }} | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} |