Skip to content

Commit f3b2ec4

Browse files
committed
chore: Add checkout fetch depth input
1 parent c0be343 commit f3b2ec4

File tree

2 files changed

+242
-1
lines changed

2 files changed

+242
-1
lines changed
Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
name: Build app image and run command
2+
3+
on:
4+
workflow_dispatch:
5+
workflow_call:
6+
inputs:
7+
# See: https://hub.docker.com/_/postgres
8+
postgres_version:
9+
description: Postgres version for running tests (eg. 13.6)
10+
required: false
11+
type: string
12+
13+
postgres_user:
14+
description: Postgres user
15+
required: false
16+
type: string
17+
18+
postgres_password:
19+
description: Postgres password
20+
required: false
21+
type: string
22+
23+
redis_image:
24+
description: Redis version for running tests (eg. 6.2)
25+
required: false
26+
type: string
27+
default: ''
28+
29+
# See: https://hub.docker.com/_/mysql
30+
mysql_version:
31+
description: MySQL version for running tests (eg. 9.1). Use root user.
32+
required: false
33+
type: string
34+
35+
mysql_root_password:
36+
description: MySQL root user password
37+
required: false
38+
type: string
39+
40+
runner:
41+
description: Set the runner for the workflow (eg. ubuntu-20.04)
42+
required: false
43+
type: string
44+
default: ubuntu-latest
45+
46+
timeout_minutes:
47+
description: Workflow timeout
48+
required: false
49+
type: number
50+
default: 10
51+
52+
image_target:
53+
description: Set the target build stage for the image (eg. test or deploy)
54+
required: false
55+
type: string
56+
57+
image_context:
58+
description: Docker context
59+
required: false
60+
type: string
61+
default: '.'
62+
63+
image_dockerfile:
64+
description: Path to Dockerfile
65+
required: false
66+
type: string
67+
68+
image_tags:
69+
description: Docker image tags
70+
required: false
71+
type: string
72+
73+
image_build_args:
74+
description: Docker build arguments
75+
required: false
76+
type: string
77+
78+
image_secret_files:
79+
description: Docker image build secret files
80+
required: false
81+
type: string
82+
83+
aws_region:
84+
description: AWS region for assuming a role
85+
required: false
86+
type: string
87+
88+
aws_role_to_assume:
89+
description: Role to be assumed for AWS authentication
90+
required: false
91+
type: string
92+
93+
buildx_platforms:
94+
description: List of the preferred platforms for Docker Buildx
95+
required: false
96+
type: string
97+
98+
selenium_version:
99+
description: Selenium version
100+
required: false
101+
type: string
102+
103+
# Command examples:
104+
# Basic Docker command
105+
# docker run app bin/ci-checks
106+
# Docker with database connection
107+
# docker run \
108+
# --env DB_HOST=127.0.0.1 \
109+
# --env DB_PORT=5432 \
110+
# --env DB_USERNAME=deploy \
111+
# --env DB_PASSWORD=password \
112+
# --network=host \
113+
# app \
114+
# bin/ci-checks
115+
# Docker with bind mounts
116+
# docker run \
117+
# --mount type=bind,src="$(pwd)"/.sample.env,dst=/app/.env \
118+
# app \
119+
# bin/ci-checsk
120+
run_command:
121+
description: Command to run, e.g. your CI suite
122+
required: true
123+
type: string
124+
125+
artifact_name:
126+
description: Name of the artifact to upload. Defaults to 'artifact' if not provided.
127+
required: false
128+
type: string
129+
default: artifact
130+
131+
artifact_path:
132+
description: |
133+
Path to the artifact to upload. If not provided no artifacts will be uploaded.
134+
Same as the path argument in actions/upload-artifact@v4 (check docs for more info).
135+
required: false
136+
type: string
137+
138+
git_ref:
139+
description: |
140+
Git reference to use for the build. Defaults to GITHUB_SHA of the event that triggered the workflow.
141+
If using `push` or `workflow_dispatch` then you do not have to pass it as the correct revision is checked out.
142+
Useful for other events like `workflow_run`, see https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows
143+
required: false
144+
type: string
145+
# See: https://github.com/actions/checkout
146+
checkout_fetch_depth:
147+
description: Number of commits to fetch. 0 indicates all history for all branches and tags.
148+
type: number
149+
required: false
150+
151+
jobs:
152+
build_image:
153+
name: Build app image and run checks
154+
runs-on: ${{ inputs.runner }}
155+
timeout-minutes: ${{ inputs.timeout_minutes }}
156+
157+
services:
158+
postgres:
159+
image: ${{ inputs.postgres_version && format('postgres:{0}', inputs.postgres_version) }}
160+
env:
161+
POSTGRES_USER: ${{ inputs.postgres_user }}
162+
POSTGRES_PASSWORD: ${{ inputs.postgres_password }}
163+
options: >-
164+
--health-cmd pg_isready
165+
--health-interval 10s
166+
--health-timeout 5s
167+
--health-retries 5
168+
ports:
169+
- 5432:5432
170+
171+
mysql:
172+
image: ${{ inputs.mysql_version && format('mysql:{0}', inputs.mysql_version) }}
173+
env:
174+
MYSQL_ROOT_PASSWORD: ${{ inputs.mysql_root_password }}
175+
options: >-
176+
--health-cmd="mysqladmin ping"
177+
--health-interval=10s
178+
--health-timeout=5s
179+
--health-retries=5
180+
ports:
181+
- 3306:3306
182+
183+
redis:
184+
image: ${{ inputs.redis_image && format('redis:{0}', inputs.redis_image) }}
185+
ports:
186+
- 6379:6379
187+
options: >-
188+
--health-cmd "redis-cli ping"
189+
--health-interval 10s
190+
--health-timeout 5s
191+
--health-retries 5
192+
193+
selenium:
194+
image: ${{ inputs.selenium_version && format('selenium/standalone-chrome:{0}', inputs.selenium_version) }}
195+
ports:
196+
- 4444:4444
197+
198+
steps:
199+
- uses: actions/checkout@v5
200+
with:
201+
ref: ${{ inputs.git_ref }}
202+
fetch-depth: ${{ inputs.checkout_fetch_depth }}
203+
204+
- name: Configure AWS credentials
205+
if: ${{ inputs.aws_role_to_assume }}
206+
uses: aws-actions/configure-aws-credentials@v5
207+
with:
208+
aws-region: ${{ inputs.aws_region }}
209+
role-to-assume: ${{ inputs.aws_role_to_assume }}
210+
211+
- name: Set up Docker Buildx
212+
id: buildx
213+
uses: docker/setup-buildx-action@v3
214+
with:
215+
platforms: ${{ inputs.buildx_platforms }}
216+
217+
- name: Build app image
218+
uses: docker/build-push-action@v6
219+
with:
220+
builder: ${{ steps.buildx.outputs.name }}
221+
context: ${{ inputs.image_context }}
222+
file: ${{ inputs.image_dockerfile }}
223+
target: ${{ inputs.image_target }}
224+
push: false
225+
load: true
226+
tags: ${{ inputs.image_tags }}
227+
build-args: ${{ inputs.image_build_args }}
228+
secret-files: ${{ inputs.image_secret_files }}
229+
cache-from: type=gha
230+
cache-to: type=gha,mode=max
231+
232+
- name: Run specified command
233+
run: ${{ inputs.run_command }}
234+
235+
- name: Upload build artifacts
236+
uses: actions/upload-artifact@v4
237+
if: ${{ inputs.artifact_path }}
238+
with:
239+
name: ${{ inputs.artifact_name }}
240+
path: ${{ inputs.artifact_path }}

.github/workflows/build-in-container.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ on:
66
jobs:
77
build-test-image-and-run-checks:
88
name: Build test image and run checks
9-
uses: infinum/rails-cicd-pipelines/.github/workflows/build-app-image-and-run-command.yml@v0.5.1
9+
uses: ./.github/workflows/build-app-image-and-run-command.yml
1010
with:
11+
checkout_fetch_depth: 0
1112
image_target: base
1213
image_tags: rails-cicd-pipelines
1314
run_command: |

0 commit comments

Comments
 (0)