Skip to content

Commit 9c6c46c

Browse files
authored
Merge pull request #85 from essentialkaos/develop
Improve GitHub Actions workflows
2 parents 2226fea + 837e3be commit 9c6c46c

File tree

6 files changed

+179
-82
lines changed

6 files changed

+179
-82
lines changed

.github/workflows/ci.yml

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ on:
88
schedule:
99
- cron: '0 13 */15 * *'
1010

11+
env:
12+
SRC_DIR: src/github.com/${{ github.repository }}
13+
1114
jobs:
1215
Go:
1316
name: Go
1417
runs-on: ubuntu-latest
1518

16-
env:
17-
SRC_DIR: src/github.com/${{ github.repository }}
18-
1919
strategy:
2020
matrix:
2121
go: [ '1.17.x', '1.18.x' ]
@@ -25,7 +25,6 @@ jobs:
2525
uses: actions/setup-go@v3
2626
with:
2727
go-version: ${{ matrix.go }}
28-
id: go
2928

3029
- name: Checkout
3130
uses: actions/checkout@v3
@@ -46,15 +45,11 @@ jobs:
4645

4746
needs: Go
4847

49-
env:
50-
SRC_DIR: src/github.com/${{ github.repository }}
51-
5248
steps:
5349
- name: Set up Go
5450
uses: actions/setup-go@v3
5551
with:
5652
go-version: '1.17.x'
57-
id: go
5853

5954
- name: Checkout
6055
uses: actions/checkout@v3
@@ -82,7 +77,7 @@ jobs:
8277
uses: actions/checkout@v3
8378

8479
- name: Login to GitHub Container Registry
85-
uses: docker/login-action@v1
80+
uses: docker/login-action@v2
8681
with:
8782
registry: ghcr.io
8883
username: ${{ github.actor }}
@@ -112,27 +107,51 @@ jobs:
112107
name: Docker Build Check
113108
runs-on: ubuntu-latest
114109

115-
needs: Hadolint
110+
needs: [Hadolint, Perfecto, Aligo]
111+
112+
env:
113+
DOCKER_FILE: Dockerfile
114+
IMAGE_NAME: sslcli
116115

117116
steps:
117+
- name: Check event type
118+
run: |
119+
if [[ "${{github.event_name}}" != "pull_request" ]] ; then
120+
echo "::notice::Event type is not 'pull_request', all job actions will be skipped"
121+
fi
122+
123+
# This step is a hack for needs+if issue with actions
124+
# More info about issue: https://github.com/actions/runner/issues/491
125+
118126
- name: Checkout
119127
uses: actions/checkout@v3
128+
if: ${{ github.event_name == 'pull_request' }}
120129

121130
- name: Login to DockerHub
122131
uses: docker/login-action@v2
123132
env:
124133
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
125-
if: ${{ env.DOCKERHUB_USERNAME != '' }}
134+
if: ${{ github.event_name == 'pull_request' && env.DOCKERHUB_USERNAME != '' }}
126135
with:
127136
username: ${{ secrets.DOCKERHUB_USERNAME }}
128137
password: ${{ secrets.DOCKERHUB_TOKEN }}
129138

139+
- name: Login to GitHub Container Registry
140+
uses: docker/login-action@v2
141+
if: ${{ github.event_name == 'pull_request' }}
142+
with:
143+
registry: ghcr.io
144+
username: ${{ github.actor }}
145+
password: ${{ secrets.GITHUB_TOKEN }}
146+
130147
- name: Build Docker image
148+
if: ${{ github.event_name == 'pull_request' }}
131149
run: |
132-
docker build -f Dockerfile -t sslcli .
150+
docker build -f ${{ env.DOCKER_FILE }} -t ${{ env.IMAGE_NAME }} .
133151
134152
- name: Show info about built Docker image
135153
uses: essentialkaos/docker-info-action@v1
154+
if: ${{ github.event_name == 'pull_request' }}
136155
with:
137-
image: sslcli
156+
image: ${{ env.IMAGE_NAME }}
138157
show-labels: true

.github/workflows/docker-push.yml

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
name: "Docker Push"
2+
3+
on:
4+
release:
5+
types: [published]
6+
schedule:
7+
- cron: '30 12 * * *'
8+
9+
permissions:
10+
packages: write
11+
contents: read
12+
13+
env:
14+
IMAGE_NAME: ${{ github.repository }}
15+
16+
jobs:
17+
Docker:
18+
name: Docker Build & Publish
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v3
24+
with:
25+
fetch-depth: 0
26+
27+
- name: Login to DockerHub
28+
uses: docker/login-action@v2
29+
with:
30+
username: ${{ secrets.DOCKERHUB_USERNAME }}
31+
password: ${{ secrets.DOCKERHUB_TOKEN }}
32+
33+
- name: Login to GitHub Container Registry
34+
uses: docker/login-action@v2
35+
with:
36+
registry: ghcr.io
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Checkout the latest tag
41+
run: |
42+
rev=$(git rev-list --tags --max-count=1)
43+
tag=$(git describe --tags "$rev")
44+
45+
if [[ -z "$tag" ]] ; then
46+
echo "::error::Can't find the latest tag"
47+
exit 1
48+
fi
49+
50+
echo -e "\033[34mRev:\033[0m $rev"
51+
echo -e "\033[34mTag:\033[0m $tag"
52+
53+
git checkout "$tag"
54+
55+
- name: Prepare metadata for build
56+
id: metadata
57+
run: |
58+
rev=$(git rev-list --tags --max-count=1)
59+
version=$(git describe --tags "$rev" | tr -d 'v')
60+
61+
if [[ -z "$version" ]] ; then
62+
echo "::error::Can't find version info"
63+
exit 1
64+
fi
65+
66+
docker_file="Dockerfile"
67+
base_image=$(grep 'FROM ' $docker_file | tail -1 | cut -f2 -d' ')
68+
69+
if [[ -z "$base_image" ]] ; then
70+
echo "::error::Can't extract base image info"
71+
exit 1
72+
fi
73+
74+
echo "::set-output name=version::$version"
75+
echo "::set-output name=dockerfile::$docker_file"
76+
echo "::set-output name=baseimage::$base_image"
77+
78+
echo -e "\033[34mVersion:\033[0m $version"
79+
echo -e "\033[34mDockerfile:\033[0m $docker_file"
80+
echo -e "\033[34mBase image:\033[0m $base_image"
81+
82+
- name: Check if build/rebuild is required
83+
id: build_check
84+
run: |
85+
if [[ "${{github.event_name}}" == "release" ]] ; then
86+
echo "::set-output name=build::true"
87+
exit 0
88+
fi
89+
90+
echo -e "::group::\033[34mDownloading built image…\033[0m"
91+
92+
if ! docker pull ghcr.io/${{env.IMAGE_NAME}}:latest ; then
93+
echo "::error::Can't download image ghcr.io/${{env.IMAGE_NAME}}:latest"
94+
exit 1
95+
fi
96+
97+
echo "::endgroup::"
98+
echo -e "::group::\033[34mDownloading base image…\033[0m"
99+
100+
if ! docker pull ${{steps.metadata.outputs.baseimage}} ; then
101+
echo "::error::Can't download image ${{steps.metadata.outputs.baseimage}}"
102+
exit 1
103+
fi
104+
105+
echo "::endgroup::"
106+
107+
base_layer=$(docker inspect "${{steps.metadata.outputs.baseimage}}" | jq -r '.[0].RootFS.Layers[-1]')
108+
109+
if [[ -z "$base_layer" ]] ; then
110+
echo "::error::Can't extract layers info from base image"
111+
exit 1
112+
fi
113+
114+
if ! docker inspect "ghcr.io/${{env.IMAGE_NAME}}:latest" | jq -r '.[0].RootFS.Layers' | grep -q "$base_layer" ; then
115+
echo "::warning::Rebuild image (reason: base image rebuilt)"
116+
echo "::set-output name=build::true"
117+
exit 0
118+
fi
119+
120+
- name: Build and push Docker image
121+
if: ${{ steps.build_check.outputs.build == 'true' }}
122+
uses: docker/build-push-action@v3
123+
with:
124+
push: true
125+
context: .
126+
file: ${{steps.metadata.outputs.dockerfile}}
127+
tags: |
128+
ghcr.io/${{env.IMAGE_NAME}}:${{steps.metadata.outputs.version}}
129+
ghcr.io/${{env.IMAGE_NAME}}:latest
130+
${{env.IMAGE_NAME}}:${{steps.metadata.outputs.version}}
131+
${{env.IMAGE_NAME}}:latest
132+
133+
- name: Show info about built Docker image
134+
uses: essentialkaos/docker-info-action@v1
135+
with:
136+
image: ${{env.IMAGE_NAME}}:latest
137+
show-labels: true

.github/workflows/ghcr.yml

Lines changed: 0 additions & 59 deletions
This file was deleted.

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<p align="center"><a href="#readme"><img src="https://gh.kaos.st/sslcli.svg"/></a></p>
22

33
<p align="center">
4-
<a href="https://goreportcard.com/report/github.com/essentialkaos/sslcli"><img src="https://goreportcard.com/badge/github.com/essentialkaos/sslcli"></a>
5-
<a href="https://codebeat.co/projects/github-com-essentialkaos-sslcli-master"><img src="https://codebeat.co/badges/edc52bb1-c807-470b-8466-b86cc0cfcdbe"></a>
6-
<a href="https://github.com/essentialkaos/sslcli/actions"><img src="https://github.com/essentialkaos/sslcli/workflows/CI/badge.svg" alt="GitHub Actions Status" /></a>
7-
<a href="https://github.com/essentialkaos/sslcli/actions?query=workflow%3ACodeQL"><img src="https://github.com/essentialkaos/sslcli/workflows/CodeQL/badge.svg" /></a>
4+
<a href="https://kaos.sh/w/sslcli/ci"><img src="https://kaos.sh/w/sslcli/ci.svg" alt="GitHub Actions CI Status" /></a>
5+
<a href="https://kaos.sh/r/sslcli"><img src="https://kaos.sh/r/sslcli.svg" alt="GoReportCard" /></a>
6+
<a href="https://kaos.sh/b/sslcli"><img src="https://kaos.sh/b/edc52bb1-c807-470b-8466-b86cc0cfcdbe.svg" alt="codebeat badge" /></a>
7+
<a href="https://kaos.sh/w/sslcli/codeql"><img src="https://kaos.sh/w/sslcli/codeql.svg" alt="GitHub Actions CodeQL Status" /></a>
88
<a href="#license"><img src="https://gh.kaos.st/apache2.svg"></a>
99
</p>
1010

@@ -112,9 +112,9 @@ Examples
112112
### Build Status
113113

114114
| Branch | Status |
115-
|--------|--------|
116-
| `master` | [![CI](https://github.com/essentialkaos/sslcli/workflows/CI/badge.svg?branch=master)](https://github.com/essentialkaos/sslcli/actions) |
117-
| `develop` | [![CI](https://github.com/essentialkaos/sslcli/workflows/CI/badge.svg?branch=develop)](https://github.com/essentialkaos/sslcli/actions) |
115+
|------------|--------|
116+
| `master` | [![CI](https://kaos.sh/w/bibop/ci.svg?branch=master)](https://kaos.sh/w/bibop/ci?query=branch:master) |
117+
| `develop` | [![CI](https://kaos.sh/w/bibop/ci.svg?branch=develop)](https://kaos.sh/w/bibop/ci?query=branch:develop) |
118118

119119
### Contributing
120120

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/essentialkaos/sslcli
33
go 1.17
44

55
require (
6-
github.com/essentialkaos/ek/v12 v12.45.0
6+
github.com/essentialkaos/ek/v12 v12.46.0
77
github.com/essentialkaos/sslscan/v13 v13.1.1
88
)
99

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
44
github.com/essentialkaos/check v1.2.1/go.mod h1:PhxzfJWlf5L/skuyhzBLIvjMB5Xu9TIyDIsqpY5MvB8=
55
github.com/essentialkaos/check v1.3.0 h1:ria+8o22RCLdt2D/1SHQsEH5Mmy5S+iWHaGHrrbPUc0=
66
github.com/essentialkaos/check v1.3.0/go.mod h1:PhxzfJWlf5L/skuyhzBLIvjMB5Xu9TIyDIsqpY5MvB8=
7-
github.com/essentialkaos/ek/v12 v12.45.0 h1:5KVZl5MAsPwxfjda+wb+cCxneQ747lU9zA5mjCA5Fyg=
8-
github.com/essentialkaos/ek/v12 v12.45.0/go.mod h1:uQUkpvaZHWR9aI8GfknZqOG5FC+G2PYJLFyMw9fdjbo=
7+
github.com/essentialkaos/ek/v12 v12.46.0 h1:TNw9YmKPf67E9L886EzhH9xUO49bROqvqHR4bzOqf/E=
8+
github.com/essentialkaos/ek/v12 v12.46.0/go.mod h1:uQUkpvaZHWR9aI8GfknZqOG5FC+G2PYJLFyMw9fdjbo=
99
github.com/essentialkaos/go-linenoise/v3 v3.3.5/go.mod h1:g4X3LhT83XT4h7xwrCLclAdMkJvS9qWBQTGNdS6y4vo=
1010
github.com/essentialkaos/sslscan/v13 v13.1.1 h1:ic02wruXM5IqkWJ8IvDxrdLYSrTe0EGwDQCryBxxTNU=
1111
github.com/essentialkaos/sslscan/v13 v13.1.1/go.mod h1:kKofHxVvSMXfPKXPgtTYXNxi+t9XbV7ZxldSC6oj5dE=

0 commit comments

Comments
 (0)