ci: define env vars in file #22
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: [ master ] | |
pull_request: | |
branches: [ master ] | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- uses: actions/checkout@v4.1.1 | |
- name: Docker Setup Buildx | |
uses: docker/setup-buildx-action@v3.0.0 | |
with: | |
buildkitd-flags: --debug | |
- name: Setup Go environment | |
uses: actions/setup-go@v5.0.0 | |
- name: Go build | |
run: go build -v ./... | |
- name: Go test | |
run: go test -v ./... | |
- name: Cache Docker layers | |
uses: actions/cache@v4.0.0 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Docker Login | |
uses: docker/login-action@v3.0.0 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Docker Metadata action | |
id: meta | |
uses: docker/metadata-action@v5.5.0 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=raw,value=${{ github.run_number }} | |
type=raw,value=latest | |
type=sha | |
- name: Build Docker image | |
uses: docker/build-push-action@v5.1.0 | |
with: | |
context: . | |
file: ./Dockerfile | |
tags: ${{ steps.meta.output.tags }} | |
labels: ${{ steps.meta.output.labels }} | |
push: ${{ github.event_name != 'pull_request' }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache |