Use workflow version from lab

This commit is contained in:
ted-cdw 2023-02-23 14:33:21 -05:00
parent 2287ef364a
commit 8cdc15ceaf

View file

@ -1,5 +1,10 @@
name: Build Flaskr App name: Build and Test
on: [push] on:
workflow_dispatch: # Enables manually running the workflow
push:
# pull_request:
# branches:
# - main
jobs: jobs:
tests: tests:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -19,13 +24,13 @@ jobs:
pip install -e examples/tutorial pip install -e examples/tutorial
- name: Lint with flake8 - name: Lint with flake8
run: | run: |
cd examples/tutorial
# stop the build if there are Python syntax errors or undefined names # stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest - name: Test with pytest
run: | run: |
pwd
cd examples/tutorial cd examples/tutorial
pytest pytest
# Build Docker image in a separate job so that it's not taited by cached python build/test files # Build Docker image in a separate job so that it's not taited by cached python build/test files
@ -37,27 +42,9 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Job vars - name: Set job vars
# Use bash string manipulation to create vars id: vars
# Note runner context isn't available in job.env, so use it here run: echo "sha_short=${GITHUB_SHA:0:10}" >> $GITHUB_OUTPUT
# https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#context-availability
shell: bash
run: |
echo "SHA_SHORT=${GITHUB_SHA:0:10}" >> ${GITHUB_ENV}
echo "REPO_LOWER_CASE=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}
CACHE_DIR="${{ runner.temp }}/.buildx-cache"
echo "CACHE_DIR=${CACHE_DIR}" >> ${GITHUB_ENV}
echo "NEW_CACHE_DIR=${CACHE_DIR}-new" >> ${GITHUB_ENV}
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Setup cache for Docker Buildx
id: setup-cache
uses: actions/cache@v2
with:
path: ${{ env.CACHE_DIR }}
key: buildx-flaskr-${{ github.sha }}
restore-keys: |
buildx-flaskr-
- name: Login to GitHub Container Registry - name: Login to GitHub Container Registry
uses: docker/login-action@v2 uses: docker/login-action@v2
with: with:
@ -68,21 +55,5 @@ jobs:
uses: docker/build-push-action@v4 uses: docker/build-push-action@v4
with: with:
context: examples/tutorial context: examples/tutorial
file: examples/Dockerfile
push: true push: true
tags: "ghcr.io/${{ env.REPO_LOWER_CASE }}:${{ env.SHA_SHORT }}" tags: "ghcr.io/${{ github.repository }}:${{ steps.vars.outputs.sha_short }}"
cache-from: type=local,src=${{ env.CACHE_DIR }}
cache-to: type=local,dest=${{ env.NEW_CACHE_DIR }}
# Only save the latest Docker build layers to new cache key, otherwise
# new cache keys will keep getting bigger indefinitely
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
# Thanks https://evilmartians.com/chronicles/build-images-on-github-actions-with-docker-layer-caching
- name: Only persist the new cache layers
run: |
echo "Showing ${CACHE_DIR}..."
ls ${CACHE_DIR}
echo "Showing ${NEW_CACHE_DIR}..."
ls ${NEW_CACHE_DIR}
rm -rf ${CACHE_DIR}
mv ${NEW_CACHE_DIR} ${CACHE_DIR}