Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lifei/fix GitHub workflow triggers #27

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ name: CI

on:
pull_request:
branches: [main]
branches:
- main
push:
branches:
- main

jobs:
build:
Expand All @@ -19,4 +23,5 @@ jobs:

- name: Run tests
run: |
uv run pytest tests -m 'not integration'
uv run pytest tests -m 'not integration'

27 changes: 23 additions & 4 deletions .github/workflows/pypi_release.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
name: PYPI Release

on:
push:
tags:
- 'v*'
workflow_run:
workflows: ["CI"]
types:
- completed

jobs:
pypi_release:
runs-on: ubuntu-latest

if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main' }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha }}

- name: Install UV
run: curl -LsSf https://astral.sh/uv/install.sh | sh
Expand All @@ -21,7 +24,23 @@ jobs:
- name: Build with UV
run: uvx --from build pyproject-build --installer uv

- name: Check tag exists
run: |
dist_file_name=$(cd dist && ls goose-ai*.tar.gz)
./scripts/check_tag_exists.sh $dist_file_name
env:
GITHUB_ENV: $GITHUB_ENV

- name: Create tag if it doesn't exist
if: env.tag_version != ''
run: |
git tag "v$tag_version"
git push origin "v$tag_version"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish
if: ${{ success() }}
uses: pypa/[email protected]
with:
user: __token__
Expand Down
18 changes: 18 additions & 0 deletions scripts/check_tag_exists.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
dist_file_name="$1"
echo "dist_file_name=$dist_file_name"

version=$(echo "$dist_file_name" | sed -E 's/^goose-ai-([0-9]+\.[0-9]+\.[0-9]+)\.tar\.gz$/\1/')
echo "version=$version"

if [ "$version" != "$dist_file_name" ]; then
git fetch --tags
tag_exists=$(git tag --list "v$version")
echo "tag_exists=$tag_exists"
fi
if [ -z "$tag_exists" ]; then
echo "version $version is not tagged yet"
echo "tag_version=$version" >> "$GITHUB_ENV"
else
echo "Tag exists"
fi