Skip to content

trying to simplify workflow and image #5

trying to simplify workflow and image

trying to simplify workflow and image #5

name: Docker
on:
push:
branches: [ "main" ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches: [ "main" ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@v3.5.0
with:
cosign-release: 'v2.2.4'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.0.0
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3.0.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Optionally increment the tag version using GitHub script
- name: Increment version
id: version
uses: actions/github-script@v6
with:
script: |
const version = 'v1'; // Change this to v1.0.0, v2, etc.
const [major, minor, patch] = version.replace('v', '').split('.').map(Number);
const newPatch = patch + 1;
return `v${major}.${minor}.${newPatch}`;
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v5.0.0
with:
context: ./images/midnight-toolkit
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.version.outputs.result }} # Use the incremented version
labels: "version=${{ steps.version.outputs.result }}" # Optional: Add a label
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
TAGS: ${{ steps.version.outputs.result }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}