Skip to content

Publish

Publish #52

Workflow file for this run

name: Publish
on:
schedule:
- cron: "0 0 1 * *"
push:
branches: [master]
pull_request:
branches: [master]
env:
REGISTRY: docker.io
G_REGISTRY: ghcr.io
IMAGE_NAME: hatamiarash7/fake-smtp
jobs:
Test:
runs-on: ubuntu-latest
steps:
- name: Checkout project
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
- name: Build the Docker image
run: docker build . --file Dockerfile --tag ${{ env.IMAGE_NAME }}:${{ github.sha }}
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: "${{ env.IMAGE_NAME }}:${{ github.sha }}"
exit-code: "0"
ignore-unfixed: true
vuln-type: "os,library"
severity: "CRITICAL,HIGH"
format: "template"
template: "@/contrib/sarif.tpl"
output: "trivy-results.sarif"
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: "trivy-results.sarif"
Github:
needs: Test
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
with:
ref: master
- id: github-image
uses: ASzc/change-string-case-action@v5
with:
string: ${{ env.G_REGISTRY }}/${{ github.repository }}:latest
- name: Get Current Date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
- name: Build image
run: |
docker build -t ${{ steps.github-image.outputs.lowercase }} --build-arg DATE_CREATED=${{ steps.date.outputs.date }} .
- name: Log into registry ${{ env.G_REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3.1.0
with:
registry: ${{ env.G_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push to ${{ env.G_REGISTRY }}
if: github.event_name != 'pull_request'
run: |
docker push ${{ steps.github-image.outputs.lowercase }}
Dockerhub:
needs: Test
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
with:
ref: master
- id: dockerhub-image
uses: ASzc/change-string-case-action@v5
with:
string: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
- name: Get Current Date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
- name: Build image
run: |
docker build -t ${{ steps.dockerhub-image.outputs.lowercase }} --build-arg DATE_CREATED=${{ steps.date.outputs.date }} .
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3.1.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push to ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
run: |
docker push ${{ steps.dockerhub-image.outputs.lowercase }}