Skip to content

Commit cb1c092

Browse files
committed
Workflows refactoring
1 parent b2b13c6 commit cb1c092

4 files changed

Lines changed: 101 additions & 80 deletions

File tree

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Docker Push"
1+
name: CD (Release)
22

33
on:
44
release:
@@ -19,15 +19,13 @@ permissions:
1919

2020
env:
2121
IMAGE_NAME: ${{ github.repository }}
22+
DOCKER_FILE: alpine
2223

2324
jobs:
24-
Docker:
25-
name: Docker Build & Publish
25+
BuildImage:
26+
name: Image Build & Publish
2627
runs-on: ubuntu-latest
2728

28-
env:
29-
DOCKER_FILE: alpine
30-
3129
steps:
3230
- name: Checkout
3331
uses: actions/checkout@v4
@@ -92,7 +90,7 @@ jobs:
9290
- name: Check if build/rebuild is required
9391
id: build_check
9492
run: |
95-
if [[ "${{github.event_name}}" == "release" ]] ; then
93+
if [[ "$GITHUB_EVENT_NAME" == "release" ]] ; then
9694
echo "build=true" >> $GITHUB_OUTPUT
9795
exit 0
9896
fi

.github/workflows/ci-pr.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: CI (PR)
2+
3+
on:
4+
pull_request:
5+
branches: [master]
6+
workflow_dispatch:
7+
inputs:
8+
force_run:
9+
description: 'Force workflow run'
10+
required: true
11+
type: choice
12+
options: [yes, no]
13+
14+
permissions:
15+
actions: read
16+
contents: read
17+
statuses: write
18+
19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.ref }}
21+
cancel-in-progress: true
22+
23+
jobs:
24+
CI:
25+
uses: ./.github/workflows/ci.yml
26+
secrets: inherit
27+
28+
ImageBuild:
29+
name: Container Image Build Check
30+
runs-on: ubuntu-latest
31+
32+
needs: CI
33+
34+
env:
35+
REGISTRY: ghcr.io
36+
37+
strategy:
38+
matrix:
39+
image: [ 'alpine' ]
40+
41+
steps:
42+
- name: Checkout
43+
uses: actions/checkout@v4
44+
45+
- name: Login to DockerHub
46+
uses: docker/login-action@v3
47+
env:
48+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
49+
if: ${{ env.DOCKERHUB_USERNAME != '' }}
50+
with:
51+
username: ${{ secrets.DOCKERHUB_USERNAME }}
52+
password: ${{ secrets.DOCKERHUB_TOKEN }}
53+
54+
- name: Login to GitHub Container Registry
55+
uses: docker/login-action@v3
56+
with:
57+
registry: ghcr.io
58+
username: ${{ github.actor }}
59+
password: ${{ secrets.GITHUB_TOKEN }}
60+
61+
- name: Build Docker image
62+
run: |
63+
docker build --build-arg REGISTRY=${REGISTRY} -f .docker/${{matrix.image}}.docker -t ${{matrix.image}} .
64+
65+
- name: Show info about built Docker image
66+
uses: essentialkaos/docker-info-action@v1
67+
with:
68+
image: ${{matrix.image}}
69+
show-labels: true

.github/workflows/ci-push.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: CI (Push)
2+
3+
on:
4+
push:
5+
branches: [master, develop]
6+
workflow_dispatch:
7+
inputs:
8+
force_run:
9+
description: 'Force workflow run'
10+
required: true
11+
type: choice
12+
options: [yes, no]
13+
14+
permissions:
15+
actions: read
16+
contents: read
17+
statuses: write
18+
19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.ref }}
21+
cancel-in-progress: true
22+
23+
jobs:
24+
CI:
25+
uses: ./.github/workflows/ci.yml
26+
secrets: inherit

.github/workflows/ci.yml

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
11
name: CI
22

33
on:
4-
push:
5-
branches: [master, develop]
6-
pull_request:
7-
branches: [master]
8-
schedule:
9-
- cron: '0 13 */15 * *'
10-
workflow_dispatch:
11-
inputs:
12-
force_run:
13-
description: 'Force workflow run'
14-
required: true
15-
type: choice
16-
options: [yes, no]
4+
workflow_call:
175

186
permissions:
197
actions: read
208
contents: read
219
statuses: write
2210

23-
concurrency:
24-
group: ${{ github.workflow }}-${{ github.ref }}
25-
cancel-in-progress: true
26-
2711
jobs:
2812
Go:
2913
name: Go
@@ -121,59 +105,3 @@ jobs:
121105
- name: Check spelling
122106
continue-on-error: true
123107
uses: crate-ci/typos@master
124-
125-
DockerBuild:
126-
name: Docker Build Check
127-
runs-on: ubuntu-latest
128-
129-
needs: [Hadolint, Perfecto, Aligo]
130-
131-
env:
132-
REGISTRY: ghcr.io
133-
134-
strategy:
135-
matrix:
136-
image: [ 'alpine' ]
137-
138-
steps:
139-
- name: Check event type
140-
run: |
141-
if [[ "${{github.event_name}}" != "pull_request" ]] ; then
142-
echo "::notice::Event type is not 'pull_request', all job actions will be skipped"
143-
fi
144-
145-
# This step is a hack for needs+if issue with actions
146-
# More info about issue: https://github.com/actions/runner/issues/491
147-
148-
- name: Checkout
149-
uses: actions/checkout@v4
150-
if: ${{ github.event_name == 'pull_request' }}
151-
152-
- name: Login to DockerHub
153-
uses: docker/login-action@v3
154-
env:
155-
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
156-
if: ${{ github.event_name == 'pull_request' && env.DOCKERHUB_USERNAME != '' }}
157-
with:
158-
username: ${{ secrets.DOCKERHUB_USERNAME }}
159-
password: ${{ secrets.DOCKERHUB_TOKEN }}
160-
161-
- name: Login to GitHub Container Registry
162-
uses: docker/login-action@v3
163-
if: ${{ github.event_name == 'pull_request' }}
164-
with:
165-
registry: ghcr.io
166-
username: ${{ github.actor }}
167-
password: ${{ secrets.GITHUB_TOKEN }}
168-
169-
- name: Build Docker image
170-
if: ${{ github.event_name == 'pull_request' }}
171-
run: |
172-
docker build --build-arg REGISTRY=${REGISTRY} -f .docker/${{matrix.image}}.docker -t ${{matrix.image}} .
173-
174-
- name: Show info about built Docker image
175-
uses: essentialkaos/docker-info-action@v1
176-
if: ${{ github.event_name == 'pull_request' }}
177-
with:
178-
image: ${{matrix.image}}
179-
show-labels: true

0 commit comments

Comments
 (0)