Skip to content

Commit

Permalink
ci: artifacts action
Browse files Browse the repository at this point in the history
  • Loading branch information
y-eight committed Nov 28, 2023
1 parent ddffee2 commit eaf4004
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 3 deletions.
97 changes: 97 additions & 0 deletions .github/workflows/artifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Artifacts

on:
workflow_call:
inputs:
publish:
description: Publish image to github registry
default: false
required: false
type: boolean
release:
description: Release build
default: false
required: false
type: boolean

permissions:
contents: read

jobs:
container-image:
name: Container image
runs-on: ubuntu-latest

permissions:
contents: read
packages: write
id-token: write
security-events: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

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

- name: Set image name
id: image-name
run: echo "value=ghcr.io/${{ github.repository }}" >> "$GITHUB_OUTPUT"

- name: Gather build metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.image-name.outputs.value }}
flavor: |
latest = false
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable={{is_default_branch}}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
if: inputs.publish

- name: Build and push image
id: build
uses: docker/build-push-action@v5
with:
tags: ${{ steps.meta.outputs.tags }}
build-args: VERSION={{version}}

- name: Set image ref
id: image-ref
run: echo "value=${{ steps.image-name.outputs.value }}@${{ steps.build.outputs.digest }}" >> "$GITHUB_OUTPUT"

- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@v0.14.0
with:
input: image
image-ref: image-ref.outputs
format: sarif
output: trivy-results.sarif
severity: "CRITICAL,HIGH"

- name: Upload Trivy scan results as artifact
uses: actions/upload-artifact@v3
with:
name: "[${{ github.job }}] Trivy scan results"
path: trivy-results.sarif
retention-days: 7

- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: trivy-results.sarif
23 changes: 23 additions & 0 deletions .github/workflows/test_sast.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test - SAST

on:
- push

permissions:
contents: read

jobs:
tests:
runs-on: ubuntu-latest

env:
GO111MODULE: on

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
args: ./...
10 changes: 7 additions & 3 deletions .github/workflows/test.yml → .github/workflows/test_unit.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
name: test
name: Test - Unit

on:
pull_request:
branches:
- main

permissions:
contents: read

jobs:
test_go:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
go-version-file: "go.mod"

- name: Test
run: |
Expand Down

0 comments on commit eaf4004

Please sign in to comment.