Fix a couple of bugs #7
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: 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: generate | |
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 ${{ matrix.name }} | |
runs-on: ubuntu-latest | |
needs: [test, generate-matrix] | |
strategy: | |
matrix: | |
include: ${{ fromJson(needs.generate-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/profile/${{ 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 |