Skip to content

Commit

Permalink
Merge pull request #15 from mikesongming/maint/13-release_triggered_c…
Browse files Browse the repository at this point in the history
…i_&_publish

release triggered ci & publish
  • Loading branch information
mikesongming authored Jun 20, 2022
2 parents 6812935 + 600083b commit 195c682
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 57 deletions.
43 changes: 43 additions & 0 deletions .github/scripts/rename_test_packages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python

"""
REV='0.7.1.post2+ga1b438c'
N_REV='0.7.2'
for pkg in `ls dist/* | grep ${REV}`;
do
n_pkg=`echo $pkg | awk -F "${REV}" "{print $1,${N_REV},$2}"`
echo $pkg '->' $n_pkg
done
"""
import os
from pathlib import Path

rev = os.environ.get("REV")
next_rev = os.environ.get("N_REV")
assert rev is not None, "env.REV is not set!"
assert next_rev is not None, "env.N_REV is not set!"

_script = Path(__file__)


def rename_pkg(pkg):
n_name = pkg.name.replace(rev, next_rev)
n_pkg = pkg.parent.joinpath(n_name)
print(n_pkg)
pkg.rename(n_pkg)


def main():
project_root = _script.parent.parent.parent
dist = project_root.joinpath("dist")

for pkg in dist.glob("*.tar.gz"):
rename_pkg(pkg)

for pkg in dist.glob("*.whl"):
rename_pkg(pkg)


if __name__ == "__main__":
main()
13 changes: 13 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ on:
required: false
type: boolean
outputs:
rev:
description: version of head ref
value: ${{ jobs.build_sdist.outputs.rev }}
next_rev:
description: next version of head ref
value: ${{ jobs.build_sdist.outputs.next_rev }}
pkg_name:
description: name of sdist
value: ${{ jobs.build_sdist.outputs.pkg_name }}
Expand Down Expand Up @@ -117,6 +123,8 @@ jobs:
if: ${{ inputs.need_sdist }}
runs-on: ubuntu-latest
outputs:
rev: ${{ steps.save.outputs.rev }}
next_rev: ${{ steps.save.outputs.next_rev }}
pkg_name: ${{ steps.save.outputs.pkg_name }}
pkg_version: ${{ steps.save.outputs.pkg_version }}
steps:
Expand All @@ -133,6 +141,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install versioningit
python -m pip install build
- name: Build sdist Package with Extension
Expand All @@ -142,6 +151,8 @@ jobs:
- name: Extract sdist package info
run: |
bash .github/scripts/extract_sdist_info.sh
echo "rev=$(python -m versioningit)" >> $GITHUB_ENV
echo "next_rev=$(python -m versioningit -n)" >> $GITHUB_ENV
- name: Upload sdist as Artifact
if: ${{ success() }}
Expand All @@ -154,5 +165,7 @@ jobs:
- name: Write outputs
id: save
run: |
echo "::set-output name=rev::${{ env.rev }}"
echo "::set-output name=next_rev::${{ env.next_rev }}"
echo "::set-output name=pkg_name::${{ env.pkg_name }}"
echo "::set-output name=pkg_version::${{ env.pkg_version }}"
82 changes: 82 additions & 0 deletions .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Publish to PYPI

on:
workflow_call:
inputs:
ref:
required: true
type: string
is_release:
required: true
type: boolean
rev:
description: version of head ref
default: ''
required: false
type: string
next_rev:
description: next version of head ref
default: ''
required: false
type: string
sdist_artifact:
default: 'sdist'
required: false
type: string
wheels_artifact:
default: 'wheels'
required: false
type: string

defaults:
run:
shell: bash

jobs:
pypa_publish:
name: ✨ publish to PYPY
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}
fetch-depth: 0

- name: Download sdist
uses: actions/download-artifact@v3
with:
name: ${{ inputs.sdist_artifact }}
path: dist

- name: Download all wheels
uses: actions/download-artifact@v3
with:
name: ${{ inputs.wheels_artifact }}
path: dist

- name: Rename packages
if: ${{ ! inputs.is_release }}
env:
REV: ${{ inputs.rev }}
N_REV: ${{ inputs.next_rev }}
run: |
python .github/scripts/rename_test_packages.py
- name: Publish package to TestPyPI
if: ${{ ! inputs.is_release }}
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
skip_existing: true
print_hash: true

- name: Publish package to PyPI
if: ${{ inputs.is_release }}
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
skip_existing: true
print_hash: true
78 changes: 21 additions & 57 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ on:
push:
pull_request:
issue_comment:
types: [created]
types: created
release:
types: released
schedule:
- cron: "30 1 * * 4"
workflow_dispatch:

jobs:
test_build:
build_package:
uses: ./.github/workflows/build.yml
if: >-
contains(github.event.head_commit.message, '[wheel build]') ||
github.event_name == 'schedule' ||
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) ||
github.event_name == 'release' ||
(github.event_name == 'pull_request' && contains(github.event.action, 'opened')) ||
(github.event.issue.pull_request && github.event.comment.body == '/build')
with:
Expand All @@ -27,31 +29,8 @@ jobs:
need_wheel: true
need_sdist: true

debug_build:
runs-on: ubuntu-latest
needs: test_build
steps:
- run: |
echo ${{ needs.test_build.outputs.pkg_name }}
echo ${{ needs.test_build.outputs.pkg_version }}
- name: Download sdist
uses: actions/download-artifact@v3
with:
name: sdist
path: dist

- name: Download all wheels
uses: actions/download-artifact@v3
with:
name: wheels
path: wheelhouse

- run: |
ls -R
test_test:
needs: test_build
run_tests:
needs: build_package
uses: ./.github/workflows/test.yml
with:
ref: >-
Expand All @@ -62,35 +41,20 @@ jobs:
python_version: "3.10"
secrets: inherit

test_comment:
needs: test_test
update_PR_Comment:
needs: run_tests
if: ${{ github.event.pull_request || github.event.issue.pull_request }}
uses: ./.github/workflows/comment.yml

test_publish:
name: ✨ publish to PYPY
needs: [test_build, test_test]
runs-on: ubuntu-latest
if: >-
needs.test_test.outputs.test_passed
steps:
- name: Download sdist
uses: actions/download-artifact@v3
with:
name: sdist
path: dist

- name: Download all wheels
uses: actions/download-artifact@v3
with:
name: wheels
path: dist

- name: Publish package to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
skip_existing: true
print_hash: true
pypa_publish:
needs: [build_package, run_tests]
uses: ./.github/workflows/publish_pypi.yml
if: needs.run_tests.outputs.test_passed
with:
ref: >-
${{ github.event.pull_request &&
github.event.pull_request.head.ref || github.ref_name
}}
is_release: ${{ github.event_name == 'release' }}
rev: ${{ needs.build_package.outputs.rev }}
next_rev: ${{ needs.build_package.outputs.next_rev }}

0 comments on commit 195c682

Please sign in to comment.