diff --git a/.github/workflows/cleanup-caches.yml b/.github/workflows/cleanup-caches.yml new file mode 100644 index 0000000..e478cec --- /dev/null +++ b/.github/workflows/cleanup-caches.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..3aef487 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -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