Skip to content

Commit fd8a8dc

Browse files
authored
Initial implementation (#2)
1 parent a089045 commit fd8a8dc

File tree

4 files changed

+124
-31
lines changed

4 files changed

+124
-31
lines changed

.github/workflows/test-negative.yml

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
name: Test example negative
1+
name: Docker not exists
22
on:
3-
# # Uncomment when test added first time to register workflow and comment it back after workflow would be registered
4-
# #
5-
# # Added pull_request to register workflow from the PR.
6-
# # Read more https://stackoverflow.com/questions/63362126/github-actions-how-to-run-a-workflow-created-on-a-non-master-branch-from-the-wo
7-
# pull_request: {}
3+
# # Uncomment when test added first time to register workflow and comment it back after workflow would be registered
4+
# #
5+
# # Added pull_request to register workflow from the PR.
6+
# # Read more https://stackoverflow.com/questions/63362126/github-actions-how-to-run-a-workflow-created-on-a-non-master-branch-from-the-wo
7+
# pull_request: {}
88
workflow_dispatch: {}
99

1010
jobs:
@@ -16,29 +16,58 @@ jobs:
1616

1717
test:
1818
runs-on: ubuntu-latest
19-
needs: [setup]
2019
continue-on-error: true
20+
needs: [setup]
2121
steps:
2222
- name: Checkout
2323
uses: actions/checkout@v3
2424

25+
- name: Build
26+
id: build
27+
uses: cloudposse/[email protected]
28+
with:
29+
registry: registry.hub.docker.com
30+
organization: ${{ github.event.repository.owner.login }}
31+
repository: ${{ github.event.repository.name }}
32+
login: ${{ secrets.DOCKERHUB_USERNAME }}
33+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
34+
workdir: ./test
35+
2536
- uses: ./
2637
id: current
2738
with:
28-
param1: 'false'
39+
registry: registry.hub.docker.com
40+
organization: ${{ github.event.repository.owner.login }}
41+
repository: ${{ github.event.repository.name }}
42+
login: ${{ secrets.DOCKERHUB_USERNAME }}
43+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
44+
tag: hfdahjkhgkhajdksah
2945

3046
outputs:
31-
result: "${{ steps.current.outputs.result1 }}"
47+
result: ${{ steps.current.conclusion }}
48+
image: ${{ steps.current.outputs.image }}
49+
tag: ${{ steps.current.outputs.tag }}
50+
builded_tag: ${{ steps.build.outputs.tag }}
3251

3352
assert:
3453
runs-on: ubuntu-latest
3554
needs: [test]
3655
steps:
3756
- uses: nick-fields/assert-action@v1
3857
with:
39-
expected: 'false'
58+
expected: 'failure'
4059
actual: "${{ needs.test.outputs.result }}"
4160

61+
- uses: nick-fields/assert-action@v1
62+
with:
63+
expected: registry.hub.docker.com/${{ github.event.repository.owner.login }}/${{ github.event.repository.name }}
64+
actual: "${{ needs.test.outputs.image }}"
65+
66+
- uses: nick-fields/assert-action@v1
67+
with:
68+
expected: hfdahjkhgkhajdksah
69+
actual: ${{ needs.test.outputs.tag }}
70+
4271
teardown:
4372
runs-on: ubuntu-latest
4473
needs: [assert]

.github/workflows/test-positive.yml

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
name: Test example positive
1+
name: Docker exists
22
on:
3-
# # Uncomment when test added first time to register workflow and comment it back after workflow would be registered
4-
# #
5-
# # Added pull_request to register workflow from the PR.
6-
# # Read more https://stackoverflow.com/questions/63362126/github-actions-how-to-run-a-workflow-created-on-a-non-master-branch-from-the-wo
7-
# pull_request: {}
3+
# # Uncomment when test added first time to register workflow and comment it back after workflow would be registered
4+
# #
5+
# # Added pull_request to register workflow from the PR.
6+
# # Read more https://stackoverflow.com/questions/63362126/github-actions-how-to-run-a-workflow-created-on-a-non-master-branch-from-the-wo
7+
# pull_request: {}
88
workflow_dispatch: {}
99

1010
jobs:
@@ -22,23 +22,52 @@ jobs:
2222
- name: Checkout
2323
uses: actions/checkout@v3
2424

25+
- name: Build
26+
id: build
27+
uses: cloudposse/[email protected]
28+
with:
29+
registry: registry.hub.docker.com
30+
organization: ${{ github.event.repository.owner.login }}
31+
repository: ${{ github.event.repository.name }}
32+
login: ${{ secrets.DOCKERHUB_USERNAME }}
33+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
34+
workdir: ./test
35+
2536
- uses: ./
2637
id: current
2738
with:
28-
param1: 'true'
39+
registry: registry.hub.docker.com
40+
organization: ${{ github.event.repository.owner.login }}
41+
repository: ${{ github.event.repository.name }}
42+
login: ${{ secrets.DOCKERHUB_USERNAME }}
43+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
44+
tag: ${{ steps.build.outputs.tag }}
2945

3046
outputs:
31-
result: "${{ steps.current.outputs.result1 }}"
47+
result: ${{ steps.current.conclusion }}
48+
image: ${{ steps.current.outputs.image }}
49+
tag: ${{ steps.current.outputs.tag }}
50+
builded_tag: ${{ steps.build.outputs.tag }}
3251

3352
assert:
3453
runs-on: ubuntu-latest
3554
needs: [test]
3655
steps:
3756
- uses: nick-fields/assert-action@v1
3857
with:
39-
expected: 'true'
58+
expected: 'success'
4059
actual: "${{ needs.test.outputs.result }}"
4160

61+
- uses: nick-fields/assert-action@v1
62+
with:
63+
expected: registry.hub.docker.com/${{ github.event.repository.owner.login }}/${{ github.event.repository.name }}
64+
actual: "${{ needs.test.outputs.image }}"
65+
66+
- uses: nick-fields/assert-action@v1
67+
with:
68+
expected: ${{ needs.test.outputs.builded_tag }}
69+
actual: ${{ needs.test.outputs.tag }}
70+
4271
teardown:
4372
runs-on: ubuntu-latest
4473
needs: [assert]

action.yml

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,57 @@
1-
name: 'Example composite GitHub action'
2-
description: 'Example composite GitHub action'
1+
name: 'Docker image exists'
2+
description: 'Check if docker image exists by pulling it'
33
44
branding:
5-
icon: 'file'
5+
icon: 'download-cloud'
66
color: 'white'
77
inputs:
8-
param1:
8+
organization:
9+
description: 'Organization'
910
required: true
10-
description: "Input parameter placeholder"
11-
default: "true"
11+
repository:
12+
description: 'Repository'
13+
required: true
14+
registry:
15+
description: 'Docker registry'
16+
required: true
17+
tag:
18+
required: true
19+
description: "Tag"
20+
login:
21+
description: 'Docker login'
22+
required: false
23+
default: ''
24+
password:
25+
description: 'Docker password'
26+
required: false
27+
default: ''
1228
outputs:
13-
result1:
14-
description: "Output result placeholder"
15-
value: "${{ steps.context.outputs.action-result }}"
29+
image:
30+
description: "Docker image name"
31+
value: ${{ steps.context.outputs.image }}
32+
tag:
33+
description: "Docker image tag"
34+
value: ${{ inputs.tag }}
1635
runs:
1736
using: "composite"
1837
steps:
19-
- id: context
38+
- uses: cloudposse/[email protected]
39+
id: context
40+
with:
41+
query: .
42+
config: |-
43+
image: ${{ inputs.registry }}/${{ inputs.organization }}/${{ inputs.repository }}
44+
45+
- name: Login
46+
uses: docker/login-action@v2
47+
if: ${{ contains(inputs.registry, '.amazonaws.com') || ( inputs.login != '' && inputs.password != '' ) }}
48+
with:
49+
registry: ${{ inputs.registry }}
50+
username: ${{ inputs.login }}
51+
password: ${{ inputs.password }}
52+
53+
- name: Pull
54+
id: pull
2055
shell: bash
2156
run: |
22-
echo "::set-output name=action-result::${{ inputs.param1 }}"
23-
57+
docker pull ${{ steps.context.outputs.image }}:${{ inputs.tag }}

test/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FROM nginx:1.23.0-alpine

0 commit comments

Comments
 (0)