Skip to content

Commit

Permalink
ci: update actions versions, add unique version for uploads to TestPyPI
Browse files Browse the repository at this point in the history
remove CUSTOM_GITHUB_TOKEN where not required
  • Loading branch information
Michele-Alberti committed Jan 23, 2024
1 parent b6ce22a commit f932fd3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/bump_version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
echo "pre_release=$pre_release" >> $GITHUB_OUTPUT
echo "pre-release: $pre_release"
- name: Check out
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.CUSTOM_GITHUB_TOKEN }}
Expand All @@ -44,17 +44,15 @@ jobs:
name: 🔗 Merge back to dev
needs: bump_version
runs-on: ubuntu-latest
if: contains(github.event.head_commit.message, 'Merge')
environment:
name: release
url: https://github.com/Michele-Alberti/data-lunch/commits/development
steps:
- name: Check out
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main
token: ${{ secrets.CUSTOM_GITHUB_TOKEN }}
- name: Set Git config
run: |
git config --local user.name "github-actions[bot]"
Expand Down
47 changes: 39 additions & 8 deletions .github/workflows/ci_cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ on:
- development

jobs:
# Always build the package
# Build the package for PyPI
build:
name: 🛠️ Build distribution 📦
# Only publish to PyPI on tag pushes and on TestPyPI if branch is development
if: startsWith(github.ref_name, 'refs/tags/v') || github.ref_name == 'development'
if: startsWith(github.ref_name, 'refs/tags/v')
runs-on: ubuntu-latest

steps:
Expand All @@ -40,7 +40,6 @@ jobs:
publish-to-pypi:
name: >-
🐍 Publish Python distribution 📦 to PyPI
if: startsWith(github.ref_name, 'refs/tags/v') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest
Expand Down Expand Up @@ -111,15 +110,14 @@ jobs:
needs:
- publish-to-pypi
runs-on: ubuntu-latest
if: contains(github.event.head_commit.message, 'Merge')

environment:
name: release
url: https://hub.docker.com/r/michelealberti/data-lunch-app

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: main
- name: Login to DockerHub
Expand All @@ -141,12 +139,45 @@ jobs:
cache-to: type=registry,ref=${{ secrets.DOCKER_HUB_USERNAME }}/data-lunch-app:buildcache,mode=max

# If on development just publish to TestPyPI
# Build the package for TestPyPI
test-build:
name: 🚧 Build test distribution 📦
# Only publish to PyPI on tag pushes and on TestPyPI if branch is development
if: github.ref_name == 'development'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Change package version to unique value
run: |
test_ver=$(git describe | sed 's/\(.*-.*\)-.*/\1/')
echo test version: $test_ver
sed -i "s/version = \".*\"/version = \"$test_ver\"/g" pyproject.toml
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/

publish-to-testpypi:
name: 🧪 Publish Python distribution 📦 to TestPyPI
needs:
- build
- test-build
runs-on: ubuntu-latest
if: github.ref_name == 'development' # only publish to PyPI on tag pushes

environment:
name: test-release
Expand All @@ -161,7 +192,7 @@ jobs:
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
- name: Publish distribution package to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
2 changes: 1 addition & 1 deletion .github/workflows/manual_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
echo "Image tag: ${{ github.event.inputs.tag }}"
echo "Description: ${{ github.event.inputs.build_description }}"
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Login to DockerHub
uses: docker/login-action@v2
with:
Expand Down

0 comments on commit f932fd3

Please sign in to comment.