Update actions/checkout action to v5 - autoclosed #406
Workflow file for this run
This file contains hidden or 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: smartcar CI/CD | |
on: [push, pull_request] | |
jobs: | |
build-base: | |
runs-on: ubuntu-latest | |
# runs-on: self-hosted | |
strategy: | |
matrix: | |
# Dockerfiles to target | |
dockerfile: [dev, rpi] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v5 | |
- name: Repo metadata | |
id: repo | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
return context.repo.repo | |
- name: Prepare | |
id: prep | |
run: | | |
DOCKER_IMAGE=ghcr.io/jrcichra/smartcar_python_base${OS} | |
VERSION=noop | |
if [ "${{ github.event_name }}" = "schedule" ]; then | |
VERSION=nightly | |
elif [[ $GITHUB_REF == refs/tags/* ]]; then | |
VERSION=${GITHUB_REF#refs/tags/} | |
elif [[ $GITHUB_REF == refs/heads/* ]]; then | |
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g') | |
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then | |
VERSION=latest | |
fi | |
elif [[ $GITHUB_REF == refs/pull/* ]]; then | |
VERSION=pr-${{ github.event.number }} | |
fi | |
TAGS="${DOCKER_IMAGE}:${VERSION}" | |
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then | |
MINOR=${VERSION%.*} | |
MAJOR=${MINOR%.*} | |
TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest" | |
elif [ "${{ github.event_name }}" = "push" ]; then | |
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}" | |
fi | |
echo ::set-output name=version::${VERSION} | |
echo ::set-output name=tags::${TAGS} | |
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') | |
env: | |
OS: ${{ matrix.dockerfile != 'dev' && '_rpi' || '' }} # arg after && needs to be truthy | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Cache Docker layers | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Login to DockerHub | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- uses: docker/build-push-action@v3 | |
with: | |
context: ./containers/python_base | |
file: ${{ matrix.dockerfile == 'dev' && './containers/python_base/Dockerfile' || './containers/python_base/Dockerfile-rpi' }} | |
platforms: ${{ matrix.dockerfile == 'dev' && 'linux/amd64' || 'linux/arm/v7' }} | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.prep.outputs.tags }} | |
labels: | | |
org.opencontainers.image.title=${{ fromJson(steps.repo.outputs.result).name }} | |
org.opencontainers.image.description=${{ fromJson(steps.repo.outputs.result).description }} | |
org.opencontainers.image.url=${{ fromJson(steps.repo.outputs.result).html_url }} | |
org.opencontainers.image.source=${{ fromJson(steps.repo.outputs.result).clone_url }} | |
org.opencontainers.image.version=${{ steps.prep.outputs.version }} | |
org.opencontainers.image.created=${{ steps.prep.outputs.created }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
org.opencontainers.image.licenses=${{ fromJson(steps.repo.outputs.result).license.spdx_id }} | |
build: | |
runs-on: ubuntu-latest | |
needs: [build-base] | |
strategy: | |
matrix: | |
# containers to build | |
containers: [dashcam, gpio, obdii, transfer, host_runner] | |
# Dockerfiles to target | |
dockerfile: [dev, rpi] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v5 | |
- name: Repo metadata | |
id: repo | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
return context.repo.repo | |
- name: Prepare | |
id: prep | |
run: | | |
DOCKER_IMAGE=ghcr.io/jrcichra/smartcar_${CONTAINER}${OS} | |
VERSION=noop | |
if [ "${{ github.event_name }}" = "schedule" ]; then | |
VERSION=nightly | |
elif [[ $GITHUB_REF == refs/tags/* ]]; then | |
VERSION=${GITHUB_REF#refs/tags/} | |
elif [[ $GITHUB_REF == refs/heads/* ]]; then | |
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g') | |
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then | |
VERSION=latest | |
fi | |
elif [[ $GITHUB_REF == refs/pull/* ]]; then | |
VERSION=pr-${{ github.event.number }} | |
fi | |
TAGS="${DOCKER_IMAGE}:${VERSION}" | |
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then | |
MINOR=${VERSION%.*} | |
MAJOR=${MINOR%.*} | |
TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest" | |
elif [ "${{ github.event_name }}" = "push" ]; then | |
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}" | |
fi | |
SHORT_SHA="sha-${GITHUB_SHA::8}" | |
echo ::set-output name=version::${VERSION} | |
echo ::set-output name=tags::${TAGS} | |
echo ::set-output name=short_sha::${SHORT_SHA} | |
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') | |
env: | |
CONTAINER: ${{ matrix.containers }} | |
OS: ${{ matrix.dockerfile != 'dev' && '_rpi' || '' }} # arg after && needs to be truthy | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Cache Docker layers | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Login to DockerHub | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- uses: docker/build-push-action@v3 | |
with: | |
context: ./containers/${{matrix.containers}} | |
file: ./containers/${{matrix.containers}}/${{ matrix.dockerfile == 'dev' && 'Dockerfile' || 'Dockerfile-rpi' }} | |
platforms: ${{ matrix.dockerfile == 'dev' && 'linux/amd64' || 'linux/arm/v7' }} | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.prep.outputs.tags }} | |
build-args: | | |
VERSION=${{ steps.prep.outputs.short_sha }} | |
labels: | | |
org.opencontainers.image.title=${{ fromJson(steps.repo.outputs.result).name }} | |
org.opencontainers.image.description=${{ fromJson(steps.repo.outputs.result).description }} | |
org.opencontainers.image.url=${{ fromJson(steps.repo.outputs.result).html_url }} | |
org.opencontainers.image.source=${{ fromJson(steps.repo.outputs.result).clone_url }} | |
org.opencontainers.image.version=${{ steps.prep.outputs.version }} | |
org.opencontainers.image.created=${{ steps.prep.outputs.created }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
org.opencontainers.image.licenses=${{ fromJson(steps.repo.outputs.result).license.spdx_id }} | |
scan: | |
runs-on: ubuntu-latest | |
needs: [build] | |
strategy: | |
matrix: | |
# containers to scan | |
containers: [dashcam, gpio, obdii, transfer, host_runner] | |
# variants to target | |
variant: [dev, rpi] | |
steps: | |
- name: Prepare | |
id: prep | |
run: | | |
SHORT_SHA="sha-${GITHUB_SHA::8}" | |
echo ::set-output name=short_sha::${SHORT_SHA} | |
- name: Scan image | |
uses: anchore/scan-action@v3 | |
with: | |
image: ghcr.io/jrcichra/smartcar_${{ matrix.containers }}${{ matrix.variant != 'dev' && '_rpi' || '' }}:${{ steps.prep.outputs.short_sha }} # arg after && needs to be truthy | |
test: | |
runs-on: ubuntu-latest | |
needs: [build] | |
strategy: | |
matrix: | |
# variants to target | |
variant: [dev, rpi] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v5 | |
- name: Repo metadata | |
id: repo | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
return context.repo.repo | |
- name: Prepare | |
id: prep | |
run: | | |
SHORT_SHA="sha-${GITHUB_SHA::8}" | |
echo ::set-output name=short_sha::${SHORT_SHA} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Test | |
run: | | |
set -x | |
mkdir ${PWD}/recordings | |
mkdir -p ${PWD}/nas/.convert | |
docker-compose -f docker-compose-test.yml up & | |
sleep 240 | |
ls -lrth "${PWD}/recordings" | |
ls -lrth "${PWD}/nas" | |
head -9999 obdii/obdii.log | |
env: | |
VARIANT: ${{ matrix.variant != 'dev' && '_rpi' || '' }} # arg after && needs to be truthy | |
SHA: ${{ steps.prep.outputs.short_sha }} |