From f95fd9167632b6fb01769da69b34962f18c26ef2 Mon Sep 17 00:00:00 2001 From: Ronald Pandolfi Date: Mon, 1 May 2023 16:12:58 -0700 Subject: [PATCH] split workflows by trigger to restrict when deploys occur --- .../{berteley-CI.yml => berteley-main.yml} | 25 ++++-- .github/workflows/berteley-pr.yml | 40 +++++++++ .github/workflows/berteley-tags.yml | 90 +++++++++++++++++++ 3 files changed, 148 insertions(+), 7 deletions(-) rename .github/workflows/{berteley-CI.yml => berteley-main.yml} (72%) create mode 100644 .github/workflows/berteley-pr.yml create mode 100644 .github/workflows/berteley-tags.yml diff --git a/.github/workflows/berteley-CI.yml b/.github/workflows/berteley-main.yml similarity index 72% rename from .github/workflows/berteley-CI.yml rename to .github/workflows/berteley-main.yml index d7297aa..5f2f5ac 100644 --- a/.github/workflows/berteley-CI.yml +++ b/.github/workflows/berteley-main.yml @@ -1,12 +1,9 @@ name: BERTeley CI +# triggers on push on: push: branches: [ main ] - tags: - - '[0-9]+.[0-9]+.[0-9]+' - pull_request: - branches: [ main ] jobs: test: @@ -25,7 +22,6 @@ jobs: - name: Install dependencies run: | - pip install -r requirements.txt pip install -e .[tests] - name: Run tests @@ -43,10 +39,25 @@ jobs: path_to_write_report: ./coverage/codecov_report.txt verbose: true - deploy: - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && github.ref == 'refs/heads/main' + # Determine if this run is triggered by a push to main WITH a tagged commit + on-tag-check: needs: test runs-on: ubuntu-latest + outputs: + on_tag: ${{ steps.contains_tag.outputs.tag }} + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + # Determine what tag is associated with this push's HEAD + - name: Find Tag + id: tagger + uses: jimschubert/query-tag-action@v1 + deploy: + needs: on-tag-check + # Only run deploy if tag does not contain a '-' (meaning no additional commits since last tag) + if: ${{ !contains(needs.on-tag-check.outputs.on_tag, '-' }} + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/berteley-pr.yml b/.github/workflows/berteley-pr.yml new file mode 100644 index 0000000..2f23c19 --- /dev/null +++ b/.github/workflows/berteley-pr.yml @@ -0,0 +1,40 @@ +name: BERTeley CD + +# triggers on PR to main +on: + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ '3.8', '3.9' ] + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + pip install -e .[tests] + + - name: Run tests + run: pytest tests --cov=./ --cov-report=xml + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v2 + with: + token: ${{ secrets.CODECOV_TOKEN }} + directory: ./coverage/reports/ + env_vars: OS, PYTHON + fail_ci_if_error: true + files: ./coverage.xml + name: codecov-umbrella + path_to_write_report: ./coverage/codecov_report.txt + verbose: true diff --git a/.github/workflows/berteley-tags.yml b/.github/workflows/berteley-tags.yml new file mode 100644 index 0000000..1c62cd5 --- /dev/null +++ b/.github/workflows/berteley-tags.yml @@ -0,0 +1,90 @@ +name: BERTeley CI + +# triggers on pushed tag +on: + push: + tags: + - '[0-9]+.[0-9]+.[0-9]+' + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ '3.8', '3.9' ] + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + pip install -e .[tests] + + - name: Run tests + run: pytest tests --cov=./ --cov-report=xml + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v2 + with: + token: ${{ secrets.CODECOV_TOKEN }} + directory: ./coverage/reports/ + env_vars: OS, PYTHON + fail_ci_if_error: true + files: ./coverage.xml + name: codecov-umbrella + path_to_write_report: ./coverage/codecov_report.txt + verbose: true + + # Determine if this run is triggered by a push to main + on-main-and-tagged-check: + needs: test + runs-on: ubuntu-latest + outputs: + on_main: ${{ steps.contains_tag.outputs.retval }} + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + # Determine if trigger ref is in main + - uses: rickstaa/action-contains-tag@v1 + id: contains_tag + with: + reference: "main" + tag: "${{ github.ref }}" + + deploy: + needs: on-main-and-tagged-check + # Only run deploy if tag in main branch + if: ${{ needs.on-main-and-tagged-check.outputs.on_main == 'true' }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Setup Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: '3.8' + + - name: Setup deploy + run: | + pip install --upgrade setuptools wheel twine + python setup.py sdist bdist_wheel + + - name: Publish package + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} + verbose: true + + - name: Github Release + uses: fnkr/github-action-ghr@v1 + env: + GHR_COMPRESS: xz + GHR_PATH: build/ + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}