-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.yml
More file actions
113 lines (103 loc) · 4.56 KB
/
action.yml
File metadata and controls
113 lines (103 loc) · 4.56 KB
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
name: Release and Delivery action
description: A simple composite GitHub Action taking care of the release and the docker container delivery of a project.
inputs:
should-release:
description: 'True if the action should perform the release of the project'
default: true
required: false
release-command:
description: 'The command executed to perform the release'
default: 'true'
required: false
should-build-and-deliver-container:
description: 'True if the action should perform the build and the delivery of the docker image of the project'
default: true
required: false
docker-file-src:
descrition: 'The Dockerfile file path to use'
default: 'Dockerfile'
required: false
container-registry-name:
description: 'Server address of the container registry. If not set then will default to Docker Hub'
default: 'false'
required: false
container-registry-username:
description: 'Username used to log against the container registry'
required: false
container-registry-password:
description: 'Password or personal access token used to log against the container registry'
required: false
image-name:
description: 'The name of docker container image to build and deliver'
default: '${{ github.repository }}'
required: false
github-token:
description: 'The GitHub token, it will be exposed in the release step as the environment variable GITHUB_TOKEN'
required: false
runs:
using: composite
steps:
- name: Checkout the repository
uses: actions/checkout@v5
with:
token: ${{ inputs.github-token }}
submodules: recursive
fetch-depth: 0
- name: Release
if: inputs.should-release == 'true'
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
shell: bash
run: |
echo "-- Start release --"
${{ inputs.release-command }}
echo "-- End release"
- shell: bash
run: echo "should-deliver-container=${{ inputs.should-build-and-deliver-container == 'true' && (inputs.should-release == 'false' || env.CONTAINER_VERSION != '') }}" >> $GITHUB_ENV
- name: Set up QEMU
if: env.should-deliver-container == 'true'
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
if: env.should-deliver-container == 'true'
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub # if the client has not provided a custom registry, then login to Docker Hub
if: env.should-deliver-container == 'true' && inputs.container-registry-name == 'false'
uses: docker/login-action@v3.0.0
with:
username: ${{ inputs.container-registry-username }}
password: ${{ inputs.container-registry-password }}
- name: Login to the Container registry # Otherwise, if the client has provided a custom registry, then login to it
if: env.should-deliver-container == 'true' && inputs.container-registry-name != 'false'
uses: docker/login-action@v3.0.0
with:
registry: ${{ inputs.container-registry-name }}
username: ${{ inputs.container-registry-username }}
password: ${{ inputs.container-registry-password }}
- id: full-image-name # Obtain the full image name depending on the selected repository
if: env.should-deliver-container == 'true'
shell: bash
run: |
if [ ${{ inputs.container-registry-name }} = 'false' ]
then
echo "image-name=${{ inputs.image-name }}" | tr '[:upper:]' '[:lower:]' >> $GITHUB_OUTPUT
else
echo "image-name=${{ inputs.container-registry-name }}/${{ inputs.image-name }}" | tr '[:upper:]' '[:lower:]' >> $GITHUB_OUTPUT
fi
- id: create-tags
if: env.should-deliver-container == 'true'
shell: bash
run: |
if [ "${{ env.CONTAINER_VERSION }}" = "" ] # Check if the user has specified a version number
then
echo "tags=${{ steps.full-image-name.outputs.image-name }}:latest" >> $GITHUB_OUTPUT
else
echo "tags=${{ steps.full-image-name.outputs.image-name }}:latest, ${{ steps.full-image-name.outputs.image-name }}:${{ env.CONTAINER_VERSION }}" >> $GITHUB_OUTPUT
fi
- name: Build and push the image to the Container registry
if: env.should-deliver-container == 'true'
uses: docker/build-push-action@v5.1.0
with:
context: .
file: "./${{ inputs.docker-file-src }}" # Dockerfile path
push: true # Push the built image to the selected container
tags: ${{ steps.create-tags.outputs.tags }}