Skip to content

Create mmm-proto-schema workflow #3

Create mmm-proto-schema workflow

Create mmm-proto-schema workflow #3

Workflow file for this run

name: Publish Proto # For tagging and publishing releases.

Check failure on line 1 in .github/workflows/proto-publish.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/proto-publish.yml

Invalid workflow file

(Line: 9, Col: 3): Unexpected value 'tags', (Line: 10, Col: 5): A sequence was not expected
on:
push:
branches:
- main # This entire workflow only runs on a push to the `main` branch (i.e. POST SUBMIT).
paths:
- 'proto/**' # Trigger only on changes to the proto directory.
tags:
- 'proto-v*' # Trigger only on pushed tags whose names start with 'proto-v'.
workflow_dispatch:
inputs:
publish_proto_to_pypi: # Creates a boolean `github.event.inputs.publish_to_pypi` variable.
description: 'Publish Proto to PyPI'
required: false
type: boolean
default: false
publish_proto_to_testpypi:
description: 'Publish Proto to TestPyPI'
required: false
type: boolean
default: false
env:
USE_PYTHON_VERSION: "3.11"
PROTO_DIR: "proto"
PYPI_PACKAGE_NAME: "mmm-proto-schema"
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/build
with:
python_version: ${{ env.USE_PYTHON_VERSION }}
working_directory: ${{ env.PROTO_DIR }}
output_path: ${{env.PROTO_DIR}}/dist/
# Check if the current `version` semver has been incremented. If so, set a
# `new_version` output.
check-proto-version:
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
new_version: ${{ steps.read_toml.outputs.new_version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Read package version from pyproject.toml
uses: SebRollen/toml-action@v1.2.0
id: read_toml
with:
file: pyproject.toml
field: 'project.version'
- name: Compare versions
run: |
CURRENT_VERSION = "${{ steps.read_toml.outputs.value }}"
PREVIOUS_TAG=$(git describe --tags --abbrev=0 --match 'v*' || { echo "Error: No matching previous tag found." >&2; exit 1; })
PREVIOUS_VERSION=$(echo "$PREVIOUS_TAG" | sed 's/^v//')
echo "CURRENT_VERSION: $CURRENT_VERSION"
echo "PREVIOUS_TAG: $PREVIOUS_TAG"
echo "PREVIOUS_VERSION: $PREVIOUS_VERSION"
if [[ $(python3 -m semver compare "$CURRENT_VERSION" "$PREVIOUS_VERSION") -eq 1 ]]; then
echo "New version detected: $CURRENT_VERSION"
NEW_VERSION=$CURRENT_VERSION
else
echo "No version increment detected."
fi
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
create-proto-tag:
needs: check-proto-version
# Only run if new_version was discovered, and do this only on the main branch.
if: >
github.ref == 'refs/heads/main'
&& needs.check-version.outputs.new_version != ''
runs-on: ubuntu-latest
permissions:
contents: write # Allow to create tags
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/create-version-tag
with:
new_version: proto-v${{ needs.check-version.outputs.new_version }}
publish-proto-to-pypi:
name: Publish Proto Python distribution to PyPI
needs:
- build
- check-proto-version
# Check if it's a tag push, or the `publish_proto_to_pypi` workflow is selected in a manual trigger.
# or if a new version was discovered in a push to the `main` branch.
if: >
github.repository == 'google/meridian' && (
(github.ref_type == 'tag' && startsWith(github.ref, 'refs/tags/proto-v'))
|| (github.event_name == 'workflow_dispatch'
&& github.event.inputs.publish_proto_to_pypi == 'true')
)
runs-on: ubuntu-latest
environment:
name: pypi-proto
url: https://pypi.org/p/${{ env.PYPI_PACKAGE_NAME }}
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
pattern: proto-python-package-distributions
path: dist/
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true
publish-proto-to-testpypi:
name: Publish Proto Python distribution to TestPyPI
needs: build
# Check if the `publish_proto_to_testpypi` workflow is selected in a manual trigger.
if: >
github.repository == 'google/meridian' && (
(github.event_name == 'workflow_dispatch'
&& github.event.inputs.publish_proto_to_testpypi == 'true')
)
runs-on: ubuntu-latest
environment:
name: testpypi-proto
url: https://test.pypi.org/p/${{ env.PYPI_PACKAGE_NAME }}
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
pattern: proto-python-package-distribution
path: dist/
- name: Publish distribution to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
verbose: true