chore: added docker for actions #4
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: Build Docker Image | |
on: | |
pull_request: | |
branches: | |
- master | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install Atlas | |
uses: ariga/setup-atlas@v0 | |
- name: Checkout code | |
uses: actions/[email protected] | |
with: | |
ref: ${{ github.event.inputs.commit || 'master' }} | |
- name: Setup Go Environment | |
uses: actions/setup-go@v4 | |
with: | |
go-version-file: go.mod | |
- name: Compile Go Binary | |
run: | | |
COMMIT=$(git rev-parse --short HEAD) | |
go build -o atlas-action -ldflags "-s -w -X main.version=$VERSION -X main.commit=$COMMIT" ./cmd/atlas-action | |
OUTPUT=$(./atlas-action --version) | |
if [[ $(echo $OUTPUT | grep -i "^atlas-action version $VERSION-$COMMIT") ]]; then | |
echo "Version=$OUTPUT" | |
else | |
echo "unexpected output: $OUTPUT, expected: atlas-action version $VERSION-$COMMIT" | |
exit 1 | |
fi | |
env: | |
CGO_ENABLED: 0 | |
VERSION: ${{ github.event.inputs.version || github.ref_name }} | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: atlas-action | |
path: ./atlas-action | |
docker: | |
needs: build | |
name: Docker (atlas-action) | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
attestations: write | |
id-token: write | |
env: | |
REGISTRY: "ghcr.io" | |
IMAGE_NAME: ${{ github.repository }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Download the binary | |
uses: actions/download-artifact@v4 | |
with: | |
name: atlas-action | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: | | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=semver,pattern=v{{major}} | |
type=sha | |
- name: Build and push | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
labels: ${{ steps.meta.outputs.labels }} | |
tags: ${{ steps.meta.outputs.tags }} | |
push: true |