-
Notifications
You must be signed in to change notification settings - Fork 10
96 lines (83 loc) · 3.1 KB
/
publish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
name: Publish Image to Quay
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: "Name of the tag for the published image"
type: string
required: true
skip_tests:
description: "Skip end to end tests when publishing an image."
type: boolean
required: false
default: false
env:
IMAGE_NAME: trestle-bot
IMAGE_REGISTRY: quay.io
jobs:
publish-image:
runs-on: 'ubuntu-latest'
permissions:
contents: read
outputs:
skip_tests: ${{ steps.check_event.outputs.event_type == 'release'
|| (steps.check_event.outputs.event_type == 'workflow_dispatch'
&& github.event.inputs.skip_tests == 'true') }}
image: ${{ env.IMAGE_REGISTRY }}/${{ vars.QUAY_ORG }}/${{ env.IMAGE_NAME }}@${{ steps.build-image.outputs.digest }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Quay
uses: docker/login-action@v3
with:
username: ${{ secrets.QUAY_USER }}
password: ${{ secrets.QUAY_TOKEN }}
registry: ${{ env.IMAGE_REGISTRY }}
- name: Check if triggered by release or workflow dispatch
id: check_event
run: echo "event_type=${{ toJson(github.event_name) }}" >> "$GITHUB_OUTPUT"
# Using intermediary variable to process event based input
- name: Set TAG environment variable for Release
if: ${{ steps.check_event.outputs.event_type == 'release' }}
run: echo "TAG=$RELEASE_VERSION" >> "$GITHUB_ENV"
env:
RELEASE_VERSION: ${{ github.event.release.tag_name }}
- name: Set TAG environment variable for Workflow Dispatch
if: ${{ steps.check_event.outputs.event_type == 'workflow_dispatch' }}
run: echo "TAG=$INPUT_VERSION" >> "$GITHUB_ENV"
env:
INPUT_VERSION: ${{ github.event.inputs.tag }}
- name: Build and export to Docker
uses: docker/build-push-action@v5
with:
load: true
tags: ${{ env.IMAGE_REGISTRY }}/${{ vars.QUAY_ORG }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}
- name: Pre-push Image Scan
uses: aquasecurity/[email protected]
with:
image-ref: ${{ env.IMAGE_REGISTRY }}/${{ vars.QUAY_ORG }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}
exit-code: 1
scanners: secret
severity: HIGH,CRITICAL,MEDIUM
- name: Build and Push
uses: docker/build-push-action@v5
id: build-image
with:
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ env.IMAGE_REGISTRY }}/${{ vars.QUAY_ORG }}/${{ env.IMAGE_NAME }}:${{ env.TAG }}
test:
permissions:
contents: read
needs: publish-image
if: ${{ needs.publish-image.outputs.skip_tests != 'true' }}
uses: ./.github/workflows/e2e.yml
with:
image: ${{ needs.publish-image.outputs.image }}