Skip to content

Commit

Permalink
feat(ci): add ci workflow file
Browse files Browse the repository at this point in the history
Release-As: 0.1.0
  • Loading branch information
scottmckendry committed Aug 22, 2024
1 parent 63da63c commit 3fbf4c7
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: CI
on:
push:

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.23
- name: Test
run: go run gotest.tools/gotestsum@latest --junitfile unit-tests.xml --format pkgname

release-please:
name: Release
runs-on: ubuntu-latest
needs: [test]
if: github.ref == 'refs/heads/main'
outputs:
release_created: ${{ steps.release-please.outputs.release_created }}
steps:
- uses: googleapis/release-please-action@v4
id: release-please
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: go

build-image:
name: Publish
if: github.ref_type == 'tag'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
uses: sigstore/cosign-installer@v3.3.0
with:
cosign-release: "v2.2.2"

# Set up BuildKit Docker container builder to be able to build
# multi-platform images and export cache
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ghcr.io/scottmckendry/mnemstart:${{ github.event.release.tag_name }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
env:
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
TAGS: ghcr.io/scottmckendry/mnemstart:${{ github.event.release.tag_name }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

0 comments on commit 3fbf4c7

Please sign in to comment.