Skip to content

Commit

Permalink
Add steps to check tag/branch patterns in CD
Browse files Browse the repository at this point in the history
  • Loading branch information
figi44 committed Aug 26, 2024
1 parent c8758fd commit 48e977f
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 39 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/cd-module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,31 @@ jobs:
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: "0"

- name: Test tag name pattern
shell: python
run: |
import re
import sys
tag_pattern = r"${{ vars.TAG_REGEX_FOR_DEPLOYMENT }}"
ref = "${{ github.ref_name }}"
if not tag_pattern:
sys.exit(0)
if not re.match(tag_pattern, ref):
print(f"::error::{ref} does not match {tag_pattern}")
sys.exit(1)
- name: Test branch name pattern
if: ${{ vars.BRANCH_REGEX_FOR_DEPLOYMENT != '' }}
run: |
git branch --all --list --format "%(refname:lstrip=-1)" --contains "${{ github.ref_name }}" | grep -E "${{ vars.BRANCH_REGEX_FOR_DEPLOYMENT }}"
- name: Setup Matrix
id: matrix
shell: python
Expand Down
100 changes: 61 additions & 39 deletions .github/workflows/cd-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ on:
workflow_call:
inputs:
testpypi:
description:
Whether to upload to testpypi instead of pypi.
description: Whether to upload to testpypi instead of pypi.
Requires secrets.PYPI_TEST_API_TOKEN to be defined.
type: boolean
required: false
Expand All @@ -17,40 +16,63 @@ jobs:
if: ${{ github.ref_type == 'tag' || github.event_name == 'release' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine build
- name: Check version
run: |
if [ -f "setup.py" ]; then
release=${{ github.ref_name }}
version=$(python setup.py --version)
test "$release" == "$version"
fi
- name: Build and publish to pypi
if: ${{ !inputs.testpypi }}
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python -m build
twine upload dist/*
- name: Build and publish to testpypi
if: ${{ inputs.testpypi }}
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TEST_API_TOKEN }}
run: |
python -m build
twine upload --repository testpypi dist/*
- uses: actions/checkout@v4
with:
fetch-depth: "0"

- name: Test tag name pattern
shell: python
run: |
import re
import sys
tag_pattern = r"${{ vars.TAG_REGEX_FOR_DEPLOYMENT }}"
ref = "${{ github.ref_name }}"
if not tag_pattern:
sys.exit(0)
if not re.match(tag_pattern, ref):
print(f"::error::{ref} does not match {tag_pattern}")
sys.exit(1)
- name: Test branch name pattern
if: ${{ vars.BRANCH_REGEX_FOR_DEPLOYMENT != '' }}
run: |
git branch --all --list --format "%(refname:lstrip=-1)" --contains "${{ github.ref_name }}" | grep -E "${{ vars.BRANCH_REGEX_FOR_DEPLOYMENT }}"
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine build
- name: Check version
run: |
if [ -f "setup.py" ]; then
release=${{ github.ref_name }}
version=$(python setup.py --version)
test "$release" == "$version"
fi
- name: Build and publish to pypi
if: ${{ !inputs.testpypi }}
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python -m build
twine upload dist/*
- name: Build and publish to testpypi
if: ${{ inputs.testpypi }}
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TEST_API_TOKEN }}
run: |
python -m build
twine upload --repository testpypi dist/*
29 changes: 29 additions & 0 deletions .github/workflows/create-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,37 @@ on:
required: false

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: "0"

- name: Test tag name pattern
shell: python
run: |
import re
import sys
tag_pattern = r"${{ vars.TAG_REGEX_FOR_DEPLOYMENT }}"
ref = "${{ github.ref_name }}"
if not tag_pattern:
sys.exit(0)
if not re.match(tag_pattern, ref):
print(f"::error::{ref} does not match {tag_pattern}")
sys.exit(1)
- name: Test branch name pattern
if: ${{ vars.BRANCH_REGEX_FOR_DEPLOYMENT != '' }}
run: |
git branch --all --list --format "%(refname:lstrip=-1)" --contains "${{ github.ref_name }}" | grep -E "${{ vars.BRANCH_REGEX_FOR_DEPLOYMENT }}"
deploy:
if: ${{ github.ref_type == 'tag' || inputs.skip_checks }}
needs: [check]
strategy:
fail-fast: false
matrix:
Expand Down

0 comments on commit 48e977f

Please sign in to comment.