Skip to content

Commit

Permalink
feat: github actions rework
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmando2000 committed Jan 10, 2024
1 parent 1b89f6b commit 07796d9
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 6 deletions.
63 changes: 59 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: CI

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]
push:
branches: ["master"]
workflow_call:

jobs:
prettier:
Expand All @@ -23,6 +24,18 @@ jobs:
run: npm install --global prettier
- name: Run Prettier
run: prettier --check --no-error-on-unmatched-pattern "**/*.{json,md,yml,yaml}"
prettier_action:
name: Prettier 2
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: Run Prettier
uses: creyD/prettier_action@v4.3
with:
prettier_options: --check --no-error-on-unmatched-pattern "**/*.{json,md,yml,yaml}"
check:
name: Mix Format
runs-on: ubuntu-latest
Expand All @@ -31,8 +44,8 @@ jobs:
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: "1.15.6"
otp-version: "26.1"
elixir-version: "1.15.7"
otp-version: "26"
- name: Restore dependencies cache
uses: actions/cache@v3
with:
Expand All @@ -43,3 +56,45 @@ jobs:
run: mix deps.get
- name: Run formatter
run: mix format --check-formatted
image_build:
name: Build Image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
hpopp/tarot-cup
tags: |
type=ref,event=pr
type=semver,pattern={{version}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and export
uses: docker/build-push-action@v5
with:
context: .
tags: ${{ steps.meta.outputs.tags }}
outputs: type=docker,dest=/tmp/image.tar
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: image
path: /tmp/image.tar
trivy:
name: Trivy Scan
runs-on: ubuntu-latest
needs: image_build
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: image
- name: Run Trivy vulnerability scanner in tarball mode
uses: aquasecurity/trivy-action@master
with:
input: image.tar
severity: "CRITICAL"
29 changes: 29 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Publish

on:
push:
tags: ["v*"]

jobs:
test_and_build:
uses: ./.github/workflows/ci.yml
secrets: inherit
image_publish:
name: Publish Image
runs-on: ubuntu-latest
needs: [image_build, trivy]
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: image
path: /tmp
- name: Publish image
run: |
docker load --input /tmp/image.tar
docker push --all-tags ${{ github.repository }}
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
elixir 1.15.6-otp-26
erlang 26.1.1
elixir 1.15.7-otp-26
erlang 26.1.2

0 comments on commit 07796d9

Please sign in to comment.