-
Notifications
You must be signed in to change notification settings - Fork 12
127 lines (111 loc) · 4.81 KB
/
gating.yaml
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
---
name: Pull request pre-check build & test
on:
pull_request:
push:
branches: [main]
jobs:
pre-commit:
name: Run the pre-commit hook
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- uses: pre-commit/[email protected]
build-container:
name: Build and push the ipa-tuura container
runs-on: ubuntu-latest
if: github.repository_owner == 'freeipa'
needs: [pre-commit]
env:
IMAGE_REGISTRY_GITHUB: ghcr.io
IMAGE_REGISTRY_QUAY: quay.io/idmops/ipa-tuura
IMAGE_TAG: ${{ github.event.number || github.ref_name }} # use PR number else ref_name -> branch name
steps:
- name: Set the ghcr.io image name derived from repository name
run: |
echo "IMAGE_REGISTRY_GITHUB=${IMAGE_REGISTRY_GITHUB}/${IMAGE,,}" >> ${GITHUB_ENV}
env:
IMAGE: '${{ github.repository }}'
- name: Log in to the GitHub Container registry
uses: redhat-actions/podman-login@v1
with:
registry: ${{ env.IMAGE_REGISTRY_GITHUB }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to Quay.io
if: github.event_name != 'pull_request'
uses: redhat-actions/podman-login@v1
with:
registry: ${{ env.IMAGE_REGISTRY_QUAY }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_TOKEN }}
- uses: actions/checkout@v3
- name: Build Image
id: build-image
uses: redhat-actions/buildah-build@v2
# yamllint disable rule:line-length
with:
tags: |
${{ format('{0}:{1}', env.IMAGE_REGISTRY_GITHUB, env.IMAGE_TAG) }}
${{ ( github.ref == 'refs/heads/main' && format('{0}:latest', env.IMAGE_REGISTRY_GITHUB) ) || '' }}
${{ ( github.ref_type == 'tag' && format('{0}:{1}', env.IMAGE_REGISTRY_GITHUB, github.ref_name) ) || '' }}
${{ ( github.event_name != 'pull_request' && format('{0}:{1}', env.IMAGE_REGISTRY_QUAY, env.IMAGE_TAG) ) || '' }}
${{ ( github.event_name != 'pull_request' && github.ref == 'refs/heads/main' && format('{0}:latest', env.IMAGE_REGISTRY_QUAY) ) || '' }}
${{ ( github.event_name != 'pull_request' && github.ref_type == 'tag' && format('{0}:{1}', env.IMAGE_REGISTRY_QUAY, github.ref_name) ) || '' }}
containerfiles: |
./Dockerfile.test
# yamllint enable rule:line-length
- name: Push to Repositories if PR is not from fork
id: push-to-repo
uses: redhat-actions/push-to-registry@v2
if: |
github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
- name: Print image url if PR is not from fork
if: |
github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name
run: echo "Image pushed to ${{ steps.push-to-repo.outputs.registry-paths }}"
pull-container:
name: Pull the ipa-tuura container if PR is not from fork
runs-on: ubuntu-latest
if: |
github.repository_owner == 'freeipa' &&
github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name
needs: [build-container]
env:
IMAGE_REGISTRY_GITHUB: ghcr.io
IMAGE_REGISTRY_QUAY: quay.io/idmops/ipa-tuura
IMAGE_TAG: ${{ github.event.number || github.ref_name }} # use PR number else ref_name -> branch name
steps:
- name: Set the ghcr.io image name derived from repository name (PR from repo)
run: |
echo "IMAGE_REGISTRY_GITHUB=${IMAGE_REGISTRY_GITHUB}/${IMAGE,,}" >> ${GITHUB_ENV}
env:
IMAGE: '${{ github.repository }}'
- name: Log in to the GitHub Container registry
uses: redhat-actions/podman-login@v1
with:
registry: ${{ env.IMAGE_REGISTRY_GITHUB }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to Quay.io
if: github.event_name != 'pull_request'
uses: redhat-actions/podman-login@v1
with:
registry: ${{ env.IMAGE_REGISTRY_QUAY }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Pull the image previously built from GitHub Container registry
run: |
podman pull ${{ env.IMAGE_REGISTRY_GITHUB }}:${{ env.IMAGE_TAG }}
podman images
- name: Pull the image previously built from Quay.io
if: github.event_name != 'pull_request'
run: |
podman pull ${{ env.IMAGE_REGISTRY_QUAY }}:${{ env.IMAGE_TAG }}
podman images