-
-
Notifications
You must be signed in to change notification settings - Fork 12
133 lines (133 loc) · 4.61 KB
/
ci.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
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
128
129
130
131
132
133
name: Continuous Integration
env:
DOCKER_IMAGE: wyrihaximusgithubactions/next-semvers
DOCKER_BUILDKIT: 1
on:
push:
branches:
- master
pull_request:
jobs:
composer-install:
runs-on: ubuntu-latest
container:
image: wyrihaximusnet/php:8.2-nts-alpine-slim-dev-root
steps:
- uses: actions/checkout@v1
- name: Cache composer packages
uses: actions/cache@v1
with:
path: ./vendor/
key: ${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }}
- name: Install Dependencies
run: composer install --ansi --no-progress --no-interaction --prefer-dist -o
qa:
strategy:
fail-fast: false
matrix:
qa: [cs, stan, psalm, unit, composer-require-checker, composer-unused]
needs: composer-install
runs-on: ubuntu-latest
container:
image: wyrihaximusnet/php:8.2-nts-alpine-slim-dev-root
steps:
- uses: actions/checkout@v1
- name: Cache composer packages
uses: actions/cache@v1
with:
path: ./vendor/
key: ${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }}
- name: Install Dependencies
run: (test -f vendor && true ) || composer install --ansi --no-progress --no-interaction --prefer-dist -o
- run: make ${{ matrix.qa }}
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
generate-ref:
name: Generate Ref
runs-on: ubuntu-latest
outputs:
REF: ${{ steps.generate-ref.outputs.ref }}
steps:
- uses: actions/checkout@v1
- id: generate-ref
name: Generate Ref
run: |
if [ "${{ github.event_name }}" == "pull_request" ] ; then
ref=$(php -r "echo str_replace('/', '-SLASH-', '${{ github.event.pull_request.head.ref }}');")
echo "$ref"
printf "ref=%s" $ref >> $GITHUB_OUTPUT
exit 0
fi
echo "${GITHUB_REF##*/}"
echo "ref=${GITHUB_REF##*/}" >> $GITHUB_OUTPUT
lint-dockerfile:
name: Lint Dockerfile
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Lint Dockerfile
uses: docker://hadolint/hadolint:latest-debian
with:
entrypoint: hadolint
args: Dockerfile-build
build-docker-image:
name: Build Docker image
needs:
- generate-ref
- lint-dockerfile
- qa
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: docker version
- run: docker images
- run: docker build --no-cache -t "${DOCKER_IMAGE}:${REF}" . -f Dockerfile-build --target=runtime
env:
REF: ${{ needs.generate-ref.outputs.ref }}
- run: docker tag "${DOCKER_IMAGE}:${REF}" "${DOCKER_IMAGE}:sha-${GITHUB_SHA}"
env:
REF: ${{ needs.generate-ref.outputs.ref }}
- run: docker run -v /tmp/trivy:/var/lib/trivy -v /var/run/docker.sock:/var/run/docker.sock -t aquasec/trivy:latest --cache-dir /var/lib/trivy image --exit-code 1 --no-progress --format table $(echo "${DOCKER_IMAGE}:${REF}")
env:
REF: ${{ needs.generate-ref.outputs.ref }}
- run: docker images
- name: Login to Docker Hub
if: contains(github.ref, 'dependabot') == false
env:
DOCKER_USER: ${{ secrets.HUB_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.HUB_PASSCODE }}
run: |
echo "${{ secrets.DOCKER_PASSWORD }}" | \
docker login \
--username "${{ secrets.DOCKER_USER }}" \
--password-stdin
- name: Push branch image to Docker Hub
if: contains(github.ref, 'dependabot') == false
run: docker push "${DOCKER_IMAGE}:${REF}"
env:
REF: ${{ needs.generate-ref.outputs.ref }}
- name: Push commit sha image to Docker Hub
if: contains(github.ref, 'dependabot') == false
run: docker push "${DOCKER_IMAGE}:sha-${GITHUB_SHA}"
function-test:
name: Functional Testing
needs:
- build-docker-image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: sed -i $(echo "s/master/sha-$GITHUB_SHA/g") Dockerfile
- name: 'Get Previous tag'
id: semvers
uses: ./
with:
version: v1.1.1
- name: Print Output
run: |
echo "${{ steps.semvers.outputs.v_patch }}"
echo "${{ steps.semvers.outputs.patch }}"
echo "${{ steps.semvers.outputs.v_minor }}"
echo "${{ steps.semvers.outputs.minor }}"
echo "${{ steps.semvers.outputs.major }}"
echo "${{ steps.semvers.outputs.v_major }}"
echo "${{ toJSON(steps.semvers.outputs) }}"