Fix format #489
Workflow file for this run
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
name: ci | |
on: | |
push: | |
branches: | |
- "**" | |
tags: | |
- "v*" | |
jobs: | |
# This job builds and updates the docker images on the LibSV's Docker Hub. It will create and push a | |
# new image if any of the following conditions apply: | |
# 1. This is a new commit to the 'main' branch. | |
# 2. If a tag for this branch does not already exist on LibSV's Docker Hub. | |
# 3. If the Dockerfile in the top project directory changed in the most recent commit. | |
docker: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 2 | |
- name: Check if Dockerfile changed in last commit | |
run: | | |
echo "DOCKERFILE_CHANGED=$(git diff --name-only HEAD~1 HEAD | grep -c Dockerfile)" >> $GITHUB_ENV | |
- name: Docker meta | |
id: docker_meta | |
uses: docker/metadata-action@v3 | |
with: | |
images: bensampson5/libsv | |
- name: Check if docker image already exists | |
run: | | |
echo '{"experimental": "enabled"}' > ~/.docker/config.json; | |
if [[ $(docker manifest inspect ${{ steps.docker_meta.outputs.tags }} 2>/dev/null) ]]; then | |
echo "DOCKER_IMAGE_EXISTS=1" >> $GITHUB_ENV; | |
else | |
echo "DOCKER_IMAGE_EXISTS=0" >> $GITHUB_ENV; | |
fi; | |
- name: Set up QEMU | |
if: env.DOCKERFILE_CHANGED == '1' || env.DOCKER_IMAGE_EXISTS == '0' || github.ref == 'refs/heads/main' | |
uses: docker/setup-qemu-action@v1 | |
- name: Set up Docker Buildx | |
if: env.DOCKERFILE_CHANGED == '1' || env.DOCKER_IMAGE_EXISTS == '0' || github.ref == 'refs/heads/main' | |
uses: docker/setup-buildx-action@v1 | |
- name: Cache Docker layers | |
if: env.DOCKERFILE_CHANGED == '1' || env.DOCKER_IMAGE_EXISTS == '0' || github.ref == 'refs/heads/main' | |
uses: actions/cache@v2 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Login to Docker Hub | |
if: github.event_name != 'pull_request' && (env.DOCKERFILE_CHANGED == '1' || env.DOCKER_IMAGE_EXISTS == '0' || github.ref == 'refs/heads/main') | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push | |
if: env.DOCKERFILE_CHANGED == '1' || env.DOCKER_IMAGE_EXISTS == '0' || github.ref == 'refs/heads/main' | |
id: docker_build | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./Dockerfile | |
platforms: linux/amd64 | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.docker_meta.outputs.tags }} | |
labels: ${{ steps.docker_meta.outputs.labels }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache | |
- name: Image digest | |
if: env.DOCKERFILE_CHANGED == '1' || env.DOCKER_IMAGE_EXISTS == '0' || github.ref == 'refs/heads/main' | |
run: echo ${{ steps.docker_build.outputs.digest }} | |
# This job runs all the LibSV builds, tests, and checks | |
libsv: | |
needs: [docker] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Docker meta | |
id: docker_meta | |
uses: docker/metadata-action@v3 | |
with: | |
images: bensampson5/libsv | |
- name: Setup GitHub environment | |
run: echo "DOCKER_RUN=docker run --rm -v $(pwd):/code bensampson5/libsv:${{ steps.docker_meta.outputs.version }}" >> $GITHUB_ENV; | |
- name: Pull docker image | |
run: docker pull bensampson5/libsv:${{ steps.docker_meta.outputs.version }} | |
- name: Build and run tests | |
run: ${{ env.DOCKER_RUN }} /code/tools/precommit.py --test | |
- name: Check format | |
run: ${{ env.DOCKER_RUN }} /code/tools/precommit.py --check-format | |
- name: Lint | |
run: ${{ env.DOCKER_RUN }} /code/tools/precommit.py --lint | |
- name: Build docs | |
run: ${{ env.DOCKER_RUN }} /code/tools/precommit.py --docs | |
- name: Build package | |
run: ${{ env.DOCKER_RUN }} /code/tools/precommit.py --build-package | |
- name: Publish package | |
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
user: __token__ | |
password: ${{ secrets.PYPI_API_TOKEN }} |