Skip to content

Commit

Permalink
ci: Use common CI/CD pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
phuongfi91 committed Nov 20, 2024
1 parent 83a18b0 commit b1b821d
Showing 1 changed file with 10 additions and 98 deletions.
108 changes: 10 additions & 98 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,113 +7,25 @@ on:

jobs:
tests:
name: Run tests and checks
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Build Docker image
run: |
docker build -t django2pydantic .
- name: Run tests
run: |
docker run --volume $(pwd):/app --workdir /app --rm django2pydantic nox -s noop
uses: NextGenContributions/cicd-pipeline/.github/workflows/test.yml@main
with:
project_name: django2pydantic

release:
# If main branch is updated, we want to release the package.
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs:
- tests
concurrency: release
runs-on: ubuntu-latest

uses: NextGenContributions/cicd-pipeline/.github/workflows/release.yml@main
with:
release_branch: main
needs: tests
permissions:
id-token: write
contents: write

continue-on-error: true

outputs:
released: ${{ steps.release.outputs.released }}

steps:
# Note: we need to checkout the repository at the workflow sha in case during the workflow
# the branch was updated. To keep PSR working with the configured release branches,
# we force a checkout of the desired release branch but at the workflow sha HEAD.
- name: Setup | Checkout Repository at workflow sha
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.sha }}

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

- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Setup | Force correct release branch on workflow sha
run: |
git checkout -B ${{ github.ref_name }} ${{ github.sha }}
- name: Action | Semantic Version Release
id: release
# Adjust tag with desired version if applicable.
uses: python-semantic-release/python-semantic-release@v9.14.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
git_committer_name: "github-actions"
git_committer_email: "actions@users.noreply.github.com"
root_options: "--strict"

- name: Build | Build the distribution packages
run: >-
python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
path: dist/
name: python-package-distributions

- name: Publish | Upload to GitHub Release Assets
uses: python-semantic-release/publish-action@v9.14.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ steps.release.outputs.tag }}


publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
uses: NextGenContributions/cicd-pipeline/.github/workflows/publish-pypi.yml@main
with:
project_name: django2pydantic
if: ${{ needs.release.outputs.released == 'true' }}
needs:
- release
runs-on: ubuntu-latest

environment:
name: testpypi
url: https://test.pypi.org/p/django2pydantic

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/

0 comments on commit b1b821d

Please sign in to comment.