Skip to content

rewrite github related code #433

rewrite github related code

rewrite github related code #433

Workflow file for this run

# Github Action Workflow enforcing our code style and running tests.
name: CI
# Trigger the workflow on both push (to the main repository)
# and pull requests (against the main repository, but from any repo).
on:
push:
branches:
- main
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.repository }}-${{ github.ref }}
cancel-in-progress: false
defaults:
run:
shell: bash
env:
# https://docs.astral.sh/uv/reference/environment/
UV_LOCKED: 1
UV_NO_SYNC: 1
UV_PYTHON_DOWNLOADS: never
permissions:
contents: read
jobs:
lint:
name: lint
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- uses: j178/prek-action@91fd7d7cf70ae1dee9f4f44e7dfa5d1073fe6623 # v1.0.11
env:
RUFF_OUTPUT_FORMAT: "github"
sessions:
name: nox sessions
runs-on: ubuntu-latest
outputs:
sessions: ${{ steps.set-sessions.outputs.sessions }}
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: set up environment
id: setup-env
uses: ./.github/actions/setup-env
with:
python-version: "3.10"
- name: export nox sessions
id: set-sessions
run: |
echo "sessions=$(nox --list -t ci --json | jq -c '[.[].session]')" >> $GITHUB_OUTPUT
ci:
name: ${{ matrix.session }}
runs-on: ubuntu-latest
needs: [sessions]
strategy:
matrix:
session: ${{ fromJson(needs.sessions.outputs.sessions) }}
env:
NOXSESSION: ${{ matrix.session }}
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: set up environment
id: setup-env
uses: ./.github/actions/setup-env
with:
python-version: "3.10"
- name: Install dependencies
run: |
nox --install-only
- name: Run nox -s ${{ matrix.session }}
run:
nox
- name: check diff
run:
git diff --exit-code
check:
name: Check CI passed
if: always()
needs:
- lint
- ci
runs-on: ubuntu-latest
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2
with:
jobs: ${{ toJSON(needs) }}
build:
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
name: Build & Push
needs: [check]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write # used to publish to GHCR
steps:
# Create a commit SHA-based tag for the container repositories
- name: Create SHA Container Tag
id: sha_tag
run: |
tag=$(cut -c 1-7 <<< $GITHUB_SHA)
echo "tag=$tag" >> $GITHUB_OUTPUT
# Check out the current repository in the `monty` subdirectory
- name: Checkout code
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
path: monty
persist-credentials: false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
- name: Login to Github Container Registry
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
# Build and push the container to the GitHub Container
# Repository. The container will be tagged as "latest"
# and with the short SHA of the commit.
- name: Build and push
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: monty/
file: monty/Dockerfile
push: true
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/monty-python:latest
cache-to: type=inline
tags: |
ghcr.io/${{ github.repository_owner }}/monty-python:latest
ghcr.io/${{ github.repository_owner }}/monty-python:${{ steps.sha_tag.outputs.tag }}
build-args: |
git_sha=${{ github.sha }}