Skip to content

Commit

Permalink
ci: combine workflows (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
natelandau authored Oct 19, 2024
1 parent 6596010 commit c95370b
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 195 deletions.
54 changes: 44 additions & 10 deletions .github/workflows/automated-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,8 @@ jobs:
strategy:
fail-fast: true
matrix:
python-version: ["3.11", "3.12"]
python-version: ["3.11", "3.12", "3.13"]
steps:
- name: Harden Security Runner
uses: step-security/harden-runner@v2
with:
egress-policy: block
disable-sudo: true
allowed-endpoints: >
*.cloudflare.docker.com:443 *.codecov.io:443 *.docker.com:443 *.docker.io:443 *.gh.neting.cc:443 *.googleapis.com:443 *.pythonhosted.org:443 api.snapcraft.io:443 astral.sh:443 codecov.io:443 github.com:443 *.githubusercontent.com:443 pypi.org:443
- name: Checkout repository
uses: actions/checkout@v4

Expand Down Expand Up @@ -86,3 +77,46 @@ jobs:
- name: Run tests
shell: bash
run: uv run pytest tests/

upload-coverage:
runs-on: ubuntu-latest
needs:
- test-python-code
steps:
- name: Checkout repository
uses: actions/checkout@v4

# ----------------------------------------------
# Install and run MongoDB
# ----------------------------------------------

- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.11.0
with:
mongodb-version: "8.0"

# ----------------------------------------------
# Setup Python, uv, and install project dependencies
# ----------------------------------------------

- name: Setup Python, uv, and the package
uses: ./.github/actions/uv-python-package

# ----------------------------------------------
# Run tests
# ----------------------------------------------

- name: Run tests with pytest
run: |
uv run coverage run
uv run coverage report
uv run coverage xml
# ----------------------------------------------
# upload coverage stats
# ----------------------------------------------
- name: Upload coverage
uses: codecov/codecov-action@v4
with:
files: reports/coverage.xml
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
77 changes: 59 additions & 18 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
name: "Create Release"

on:
workflow_dispatch:
push:
tags:
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10
Expand All @@ -10,27 +11,13 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: write

jobs:
autorelease:
create-gh-release:
name: Create Release
runs-on: "ubuntu-latest"
strategy:
fail-fast: true
matrix:
python-version: ["3.11"]
permissions:
contents: write
steps:
- name: Harden Security Runner
uses: step-security/harden-runner@v2
with:
egress-policy: block
disable-sudo: true
allowed-endpoints: >
*.cloudflare.docker.com:443 *.codecov.io:443 *.docker.com:443 *.docker.io:443 *.gh.neting.cc:443 *.googleapis.com:443 *.pythonhosted.org:443 api.snapcraft.io:443 astral.sh:443 codecov.io:443 github.com:443 *.githubusercontent.com:443 pypi.org:443
- name: Checkout repository
uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -86,6 +73,60 @@ jobs:
uses: softprops/action-gh-release@v2
with:
body: ${{join(fromJson(steps.generate_notes.outputs.notes).notes, '')}}
draft: true
draft: false
make_latest: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build-and-push-docker-image:
needs: create-gh-release
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

# ----------------------------------------------
# Publish the Docker container to the registry
# ----------------------------------------------

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: latest=true
tags: |
type=ref,event=tag
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to the Container registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=Valentina Noir Disord bot
80 changes: 0 additions & 80 deletions .github/workflows/publish-to-ghcr.yml

This file was deleted.

87 changes: 0 additions & 87 deletions .github/workflows/update-codecov.yml

This file was deleted.

0 comments on commit c95370b

Please sign in to comment.