-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e810d4
commit e3f94f9
Showing
1 changed file
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
name: Code CI | ||
|
||
on: | ||
schedule: | ||
- cron: "0 8 * * 3" | ||
env: | ||
# The target python version, which must match the Dockerfile version | ||
CONTAINER_PYTHON: "3.10" | ||
|
||
jobs: | ||
dist: | ||
runs-on: "ubuntu-latest" | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
# Need this to get version number from last tag | ||
fetch-depth: 0 | ||
|
||
- name: Build sdist and wheel | ||
run: | | ||
export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) && \ | ||
pipx run build | ||
- name: Upload sdist and wheel as artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: dist | ||
path: dist | ||
|
||
- name: Check for packaging errors | ||
run: pipx run twine check --strict dist/* | ||
|
||
- name: Install python packages | ||
uses: ./.github/actions/install_requirements | ||
with: | ||
python_version: ${{env.CONTAINER_PYTHON}} | ||
requirements_file: requirements.txt | ||
install_options: dist/*.whl | ||
|
||
- name: Test module --version works using the installed wheel | ||
# If more than one module in src/ replace with module name to test | ||
run: python -m $(ls src | head -1) --version | ||
|
||
container: | ||
needs: [dist] | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
env: | ||
TEST_TAG: "testing" | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
# Need this to get version number from last tag | ||
fetch-depth: 0 | ||
|
||
# image names must be all lower case | ||
- name: Generate image repo name | ||
run: echo IMAGE_REPOSITORY=ghcr.io/$(tr '[:upper:]' '[:lower:]' <<< "${{ github.repository }}") >> $GITHUB_ENV | ||
|
||
# Fetch latest tag on this branch | ||
- name: Fetch latest tag | ||
run: echo "LATEST_TAG=git tag | sort --version-sort | tail -n1" >> $GITHUB_ENV | ||
|
||
- name: Download wheel and lockfiles | ||
uses: actions/download-artifact@v3 | ||
with: | ||
path: artifacts/ | ||
|
||
- name: Log in to GitHub Docker Registry | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Build and export to Docker local cache | ||
uses: docker/build-push-action@v4 | ||
with: | ||
# Note build-args, context, file, and target must all match between this | ||
# step and the later build-push-action, otherwise the second build-push-action | ||
# will attempt to build the image again | ||
build-args: | | ||
PIP_OPTIONS=-r lockfiles/requirements.txt dist/*.whl | ||
context: artifacts/ | ||
file: ./Dockerfile | ||
target: runtime | ||
load: true | ||
tags: ${{ env.TEST_TAG }} | ||
# If you have a long docker build (2+ minutes), uncomment the | ||
# following to turn on caching. For short build times this | ||
# makes it a little slower | ||
#cache-from: type=gha | ||
#cache-to: type=gha,mode=max | ||
|
||
- name: Test cli works in cached runtime image | ||
run: docker run docker.io/library/${{ env.TEST_TAG }} --version | ||
|
||
- name: Create tags for publishing image | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: ${{ env.IMAGE_REPOSITORY }} | ||
# Add the "edge" tag on all commits to the "integration" branch. | ||
# Add the "latest" tag to repository tags only | ||
tags: | | ||
type=ref,event=tag | ||
type=raw,value=latest | ||
type=semver,pattern={{version}}value=${{ env.LATEST_TAG }} | ||
- name: Push cached image to container registry | ||
uses: docker/build-push-action@v3 | ||
# This does not build the image again, it will find the image in the | ||
# Docker cache and publish it | ||
with: | ||
# Note build-args, context, file, and target must all match between this | ||
# step and the previous build-push-action, otherwise this step will | ||
# attempt to build the image again | ||
build-args: | | ||
PIP_OPTIONS=-r lockfiles/requirements.txt dist/*.whl | ||
context: artifacts/ | ||
file: ./Dockerfile | ||
target: runtime | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |