Skip to content

Commit

Permalink
create workflow (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
rifkiyupra authored Feb 12, 2025
1 parent 8ef7013 commit 74b3d89
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/cleanup-caches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: cleanup caches by a branch

on:
pull_request:
types:
- closed

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Expose GitHub Runtime
uses: crazy-max/ghaction-github-runtime@v3

- name: Cleanup
run: |
echo "Fetching list of cache key"
cacheKeysForPR=$(gh cache list --ref $BRANCH --limit 100 --json id --jq '.[].id')
## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
do
gh cache delete $cacheKey
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge
75 changes: 75 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Build Snort3 Docker Image

on:
push:
branches:
- main
tags:
- "v*"
pull_request:
branches:
- main # Optional: Run the workflow on PRs target

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
BUILDER_NAME: mybuilder
BUILD_PLATFORMS_TARGET: linux/amd64,linux/arm64

permissions:
contents: read
packages: write
attestations: write
id-token: write

jobs:
build-debian:
runs-on: image-builder
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
logout: false

- name: Extract metadata (tags, labels) for Docker
id: meta
if: github.event_name != 'pull_request'
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=auto
prefix=
suffix=
- name: Expose GitHub Runtime
if: github.event_name != 'pull_request'
uses: crazy-max/ghaction-github-runtime@v3

- name: Build
id: push
uses: docker/build-push-action@v6
with:
context: .
file: ./dockerfiles/debian.dockerfile
platforms: ${{ env.BUILD_PLATFORMS_TARGET }}
push: ${{ github.event_name != 'pull_request' }}
builder: ${{ env.BUILDER_NAME }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Generate artifact attestation
if: github.event_name != 'pull_request'
uses: actions/attest-build-provenance@v2
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true

0 comments on commit 74b3d89

Please sign in to comment.