@@ -13,98 +13,211 @@ name: ci
1313# or API.
1414on :
1515 workflow_dispatch :
16- # Inputs the workflow accepts.
17- inputs :
18- version :
19- # Friendly description to be shown in the UI instead of 'name'
20- description : ' Version'
21- # Default value if no value is explicitly provided
22- default : ' 1.9.1'
23- # Input has to be provided for the workflow to run
24- required : true
25- ls :
26- description : ' ls'
27- default : ' ls2'
28- required : true
16+ pull_request :
17+ paths :
18+ - ' Dockerfile'
19+ - ' LS'
20+ - ' VERSION'
21+ push :
22+ branches :
23+ - main
24+ paths :
25+ - ' Dockerfile'
26+ - ' LS'
27+ - ' VERSION'
28+
29+ env :
30+ # How long to sleep before running the tests (gives the application time to start)
31+ GOSS_SLEEP : 30
2932
3033jobs :
31- main :
34+ prep :
35+ runs-on : ubuntu-latest
36+ outputs :
37+ version : ${{ steps.prep.outputs.version }}
38+ checksum : ${{ steps.prep.outputs.checksum }}
39+ ls : ${{ steps.prep.outputs.ls }}
40+ goss : ${{ steps.prep.outputs.goss }}
41+ push : ${{ steps.prep.outputs.push }}
42+ tag : ${{ steps.prep.outputs.version }}-ls${{ steps.prep.outputs.ls }}
43+ repo_name : ${{ steps.prep.outputs.repo_name }}
44+ date : ${{ steps.prep.outputs.date }}
45+
46+ steps :
47+ - name : Checkout
48+ uses : actions/checkout@v2.3.4
49+
50+ # Define if tests and push should be run against which versions/platforms
51+ - name : Prepare
52+ id : prep
53+ run : |
54+ VERSION=$(cat ./VERSION)
55+ echo ::set-output name=version::${VERSION}
56+ LS=$(cat ./LS)
57+ echo ::set-output name=ls::${LS}
58+ REPO_NAME=$(echo "${{ github.event.repository.name }}" | sed 's/[^-]*-//')
59+ echo ::set-output name=repo_name::${REPO_NAME}
60+ DATE=$(date -u +%Y-%m-%dT%H%M%SZ)
61+ echo ::set-output name=date::${DATE}
62+ if test -f "./CHECKSUM"; then
63+ CHECKSUM=$(cat ./CHECKSUM)
64+ echo ::set-output name=checksum::${CHECKSUM}
65+ else
66+ echo ::set-output name=checksum::""
67+ fi
68+ if test -f "./goss.yaml"; then
69+ echo ::set-output name=goss::true
70+ else
71+ echo ::set-output name=goss::false
72+ fi
73+ if [ "${{github.event_name}}" == "pull_request" ]; then
74+ echo ::set-output name=push::false
75+ else
76+ echo ::set-output name=push::true
77+ fi
78+
79+ tag-does-not-exist :
80+ runs-on : ubuntu-latest
81+ needs : prep
82+ outputs :
83+ exists : ${{ steps.checkTag.outputs.exists }}
84+ steps :
85+ - name : Check if tag already exists
86+ uses : mukunku/tag-exists-action@v1.0.0
87+ id : checkTag
88+ with :
89+ tag : ${{ needs.prep.outputs.tag }}
90+ env :
91+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
92+
93+ - name : Fail if tag already exists
94+ id : set
95+ run : |
96+ if ${{ steps.checkTag.outputs.exists }} == true; then
97+ echo "${{needs.prep.outputs.tag}} already exists"
98+ exit 1
99+ fi
100+
101+ build :
32102 runs-on : ubuntu-latest
103+ if : always() # Run regardless if tag-does-not-exist fails
104+ needs :
105+ - prep
106+ - tag-does-not-exist
33107 steps :
34- -
35- name : Get tag
36- run : echo "tag=${{ github.event.inputs.version }}-${{ github.event.inputs.ls }}" >> $GITHUB_ENV
37- -
38- name : Remove docker from the repo name
39- run : echo "repo_name=$(echo "${{ github.event.repository.name }}" | sed 's/[^-]*-//')" >> $GITHUB_ENV
40- -
41- name : Get current date
42- run : echo "date=$(date -u +%Y-%m-%dT%H%M%SZ)" >> $GITHUB_ENV
43- -
44- name : Checkout
45- uses : actions/checkout@v2
46- -
47- name : Set up QEMU
48- uses : docker/setup-qemu-action@v1
49- -
50- name : Set up Docker Buildx
51- uses : docker/setup-buildx-action@v1
108+ - name : Checkout
109+ uses : actions/checkout@v2.3.4
110+
111+ - name : Set up QEMU
112+ uses : docker/setup-qemu-action@v1.1.0
113+
114+ - name : Set up Docker Buildx
115+ uses : docker/setup-buildx-action@v1.3.0
52116 with :
53117 driver-opts : image=moby/buildkit:master
54- -
55- name : Cache Docker layers
56- uses : actions/cache@v2.1.4
118+
119+ - name : Cache Docker layers
120+ uses : actions/cache@v2.1.5
57121 with :
58122 path : /tmp/.buildx-cache
59123 key : ${{ runner.os }}-buildx-${{ github.sha }}
60124 restore-keys : |
61125 ${{ runner.os }}-buildx-
62- -
63- name : Login to DockerHub
64- uses : docker/login-action@v1
126+
127+ # Install the GOSS testing framework
128+ - name : Set up goss/dgoss
129+ uses : e1himself/goss-installation-action@v1.0.3
130+ if : needs.prep.outputs.goss == 'true'
131+ with :
132+ version : ' v0.3.16'
133+
134+ # Creates a local build to run tests on
135+ - name : Build and Load local test-container
136+ uses : docker/build-push-action@v2
137+ if : needs.prep.outputs.goss == 'true'
138+ with :
139+ build-args : |
140+ VERSION=${{ needs.prep.outputs.version }}
141+ CHECKSUM=${{ needs.prep.outputs.checksum }}
142+ context : .
143+ file : ./Dockerfile
144+ load : true
145+ tags : |
146+ ghcr.io/${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:test
147+ cache-from : type=local,src=/tmp/.buildx-cache
148+ cache-to : type=local,mode=max,dest=/tmp/.buildx-cache-new
149+
150+ # Run GOSS tests if included with the container
151+ - name : Run GOSS tests
152+ if : needs.prep.outputs.goss == 'true'
153+ env :
154+ GOSS_FILE : ./goss.yaml
155+ run : |
156+ dgoss run ghcr.io/${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:test
157+
158+ - name : Login to DockerHub
159+ uses : docker/login-action@v1.9.0
160+ if : github.event_name != 'pull_request' && needs.tag-does-not-exist.outputs.exists == 'false'
65161 with :
66162 username : ${{ secrets.DOCKERHUB_USERNAME }}
67163 password : ${{ secrets.DOCKERHUB_TOKEN }}
68- -
69- name : Login to GitHub Container Registry
70- uses : docker/login-action@v1
164+
165+ - name : Login to GitHub Container Registry
166+ uses : docker/login-action@v1.9.0
167+ if : github.event_name != 'pull_request' && needs.tag-does-not-exist.outputs.exists == 'false'
71168 with :
72169 registry : ghcr.io
73170 username : ${{ github.repository_owner }}
74171 password : ${{ secrets.CR_PAT }}
75- -
76- name : Login to Quay Registry
77- uses : docker/login-action@v1
172+
173+ - name : Login to Quay Registry
174+ uses : docker/login-action@v1.9.0
175+ if : github.event_name != 'pull_request' && needs.tag-does-not-exist.outputs.exists == 'false'
78176 with :
79177 registry : quay.io
80178 username : ${{ secrets.QUAY_USERNAME }}
81179 password : ${{ secrets.QUAY_TOKEN }}
82- -
83- name : Build and push
84- uses : docker/build-push-action@v2.3 .0
180+
181+ - name : Build and push
182+ uses : docker/build-push-action@v2.4 .0
85183 with :
86184 context : .
87185 file : ./Dockerfile
88186 platforms : linux/amd64,linux/arm/v7,linux/arm64
89- push : true
187+ push : ${{ needs.prep.outputs.push }}
90188 build-args : |
91- BUILD_DATE=${{ env.date }}
92- VERSION=${{ github.event.inputs.version }}
189+ BUILD_DATE=${{ needs.prep.outputs.date }}
190+ VERSION=${{ needs.prep.outputs.version }}
191+ CHECKSUM=${{ needs.prep.outputs.checksum }}
93192 tags : |
94- ${{ github.repository_owner }}/${{ env.repo_name }}:latest
95- ${{ github.repository_owner }}/${{ env.repo_name }}:${{ env.tag }}
96- ghcr.io/${{ github.repository_owner }}/${{ env.repo_name }}:latest
97- ghcr.io/${{ github.repository_owner }}/${{ env.repo_name }}:${{ env.tag }}
98- quay.io/${{ github.repository_owner }}/${{ env.repo_name }}:latest
99- quay.io/${{ github.repository_owner }}/${{ env.repo_name }}:${{ env.tag }}
100- -
101- name : Create Release
193+ ${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:latest
194+ ${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:${{needs.prep.outputs.tag}}
195+ ghcr.io/${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:latest
196+ ghcr.io/${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:${{needs.prep.outputs.tag}}
197+ quay.io/${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:latest
198+ quay.io/${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:${{needs.prep.outputs.tag}}
199+ cache-from : type=local,src=/tmp/.buildx-cache
200+ cache-to : type=local,mode=max,dest=/tmp/.buildx-cache-new
201+
202+ # This ugly bit is necessary if you don't want your cache to grow forever
203+ # till it hits GitHub's limit of 5GB.
204+ # Temp fix
205+ # https://github.com/docker/build-push-action/issues/252
206+ # https://github.com/moby/buildkit/issues/1896
207+ - name : Move cache
208+ if : needs.prep.outputs.push == 'true'
209+ run : |
210+ rm -rf /tmp/.buildx-cache
211+ mv /tmp/.buildx-cache-new /tmp/.buildx-cache
212+
213+ - name : Create Release
102214 id : create_release
103- uses : actions/create-release@v1
215+ uses : actions/create-release@v1.1.4
216+ if : github.event_name != 'pull_request' && needs.tag-does-not-exist.outputs.exists == 'false'
104217 env :
105218 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
106219 with :
107- tag_name : ${{ env. tag }}
108- release_name : ${{ env. tag }}
220+ tag_name : ${{needs.prep.outputs. tag}}
221+ release_name : ${{needs.prep.outputs. tag}}
109222 draft : false
110- prerelease : false
223+ prerelease : false
0 commit comments