Skip to content

newer api

newer api #3

Workflow file for this run

name: Ship
on:
push:
branches:
- "main"
env:
REGISTRY: ghcr.io
jobs:
test:
name: Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.21"
- name: Test
run: go test -v ./...
generate-matrix:
name: Generate Matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate.outputs.matrix }}
steps:
- name: Checkout code
uses: actions/checkout@v3
# Spawn a job for each dir in ./cmd
- name: Generate matrix
id: matrix
run: |
dirs=$(find ./cmd -mindepth 1 -maxdepth 1 -type d)
matrix=$(for dir in $dirs; do
name=$(basename "$dir")
echo "{ \"dir\": \"$dir\", \"name\": \"$name\" }"
done | jq -R -s -c 'split("\n") | map(select(length > 0)) | map(fromjson)')
echo "matrix=$matrix" >> $GITHUB_OUTPUT
build:
name: Build and Push
runs-on: ubuntu-latest
needs: test
strategy:
matrix:
include: ${{ fromJson(needs.matrix.outputs.matrix) }}
steps:
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
- name: Login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v3
name: Check out code
- name: Construct metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/TheLab-ms/${{ matrix.name }}
tags: |
type=sha
- name: Build and push image
uses: docker/build-push-action@v5
with:
push: true
file: ${{ matrix.dir }}/Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max