Skip to content

Commit

Permalink
CI: Upload binaries on release
Browse files Browse the repository at this point in the history
  • Loading branch information
p1gp1g committed Nov 12, 2023
1 parent 8f8d7cd commit d0f6ce5
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 9 deletions.
26 changes: 17 additions & 9 deletions .github/workflows/image.yml → .github/workflows/cron.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
name: Build Container image
name: Cron to rebuild latest

on:
workflow_dispatch:
schedule:
# rebuild latest regulary - to resolve CVEs in base images
- cron: "0 10 * * *"
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+"

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
fetch-tags: true
filter: blob:none
fetch-depth: 0

- name: Checkout last commit
id: checkout
run: |
LAST_TAG=$(git for-each-ref refs/tags --sort=-authordate --format='%(refname:short)' | grep '^[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]$' | head -n1)
echo "LAST_TAG: $LAST_TAG"
echo "tag=$LAST_TAG" >> "$GITHUB_OUTPUT"
git checkout $LAST_TAG
- name: Docker meta
id: meta
Expand All @@ -27,9 +35,9 @@ jobs:
tags: |
type=schedule
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=semver,pattern={{version}},value=${{ steps.checkout.outputs.tag }}
type=semver,pattern={{major}}.{{minor}},value=${{ steps.checkout.outputs.tag }}
type=semver,pattern={{major}},value=${{ steps.checkout.outputs.tag }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand Down
95 changes: 95 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Release

on:
workflow_dispatch:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+"

jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- TARGET: amd64
PLATFORM: linux/amd64
- TARGET: arm64
PLATFORM: linux/arm64/v8
- TARGET: armv7
PLATFORM: linux/arm/v7
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
ghcr.io/${{ github.repository }}
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
id: build
uses: docker/build-push-action@v5
with:
push: ${{ github.event_name != 'pull_request' }}
load: true
file: Containerfile
platforms: ${{ matrix.PLATFORM }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Copy artifacts
run: |
mkdir -p artifacts
if [[ $GITHUB_REF_TYPE =~ ^tag$ ]]; then
TAG=$GITHUB_REF_NAME
else
TAG=$GITHUB_SHA
fi
docker run --rm --entrypoint=cat ghcr.io/${{ github.repository }} /usr/local/bin/mollysocket > artifacts/mollysocket-${{ matrix.TARGET }}-$TAG
- name: Archive artifact
uses: actions/upload-artifact@v2
with:
name: artifacts
path: |
./artifacts
publish:
name: Publish
needs: build
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/') }}

steps:
- uses: actions/checkout@v4

- name: Download artifacts
uses: actions/download-artifact@v3

- name: Create release draft
run: gh release create -d -t "$GITHUB_REF_NAME" "$GITHUB_REF_NAME" ./artifacts/*
env:
GITHUB_TOKEN: ${{ secrets.PUBLISH_PAT || secrets.GITHUB_TOKEN }}

0 comments on commit d0f6ce5

Please sign in to comment.