-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
153 lines (142 loc) · 5.18 KB
/
action.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: "Build Docker Image"
description: "Build Docker image for arbitrary revision/branch/tag and push to registry"
inputs:
tag:
description: Revision, tag, or branch to build
required: true
default: ${{ github.event.repository.default_branch }}
img_tag:
description: Tag applied to the container image.
image:
description: >-
Image to build, e.g. ghcr.io/organization/image.
required: true
registry:
description: >-
Registry that hosts these images; by default, ghcr.io.
default: ghcr.io
registry_username:
description: >-
Username for logging in to registry. For GHCR (and by default), set to github.actor.
default: ${{ github.actor }}
registry_token:
description: >-
Token for logging in to registry. For GHCR (and by default), set to github.token.
default: ${{ github.token }}
build-args:
description: >-
Arguments to pass to docker build
required: false
dockerfile:
description: >-
Which file to use to build the image; by default, Dockerfile
default: Dockerfile
push_latest:
description: >-
Update 'latest' tag when pushing
default: false
submodules:
description: >-
Whether to checkout submodules (as for actions@v3) and thence build them into the image. Set to false by default as for checkout. If you use submodules, you probably want to set this.
default: false
platforms:
description: >-
Build images for cross platform support.
default: "linux/amd64,linux/arm64"
rebuild:
description: Rebuild the image manually?
default: false
gh_event:
description: The name of the event that triggered the parent workflow.
outputs:
ghc_img:
description: "Export GHCR.io package resource URL"
value: ${{ steps.ghc_img_id.outputs.ghc_img }}
runs:
using: composite
steps:
- name: Set Inputs & Outputs
id: set_inputs
shell: bash
run: |
if [ "${{ github.event_name }}" == "workflow_run" ]; then
echo "ref=${{ github.sha }}" >> $GITHUB_OUTPUT
echo "push_latest=true" >> $GITHUB_OUTPUT
else
# workflow_dispatch or other trigger
echo "ref=${{ inputs.tag }}" >> $GITHUB_OUTPUT
echo "push_latest=${{ inputs.push_latest }}" >> $GITHUB_OUTPUT
echo "img_tag=${{ inputs.img_tag }}" >> $GITHUB_OUTPUT
fi
- name: Clone latest repository
uses: actions/checkout@v4
with:
ref: ${{ steps.set_inputs.outputs.ref }}
submodules: ${{ inputs.submodules }}
- name: Find commit for tag
id: tag_check
uses: hathitrust/github_actions/validate-tag@v1
with:
tag: ${{ steps.set_inputs.outputs.ref }}
- name: Log into container registry
uses: docker/login-action@v3
with:
registry: ${{ inputs.registry }}
username: ${{ inputs.registry_username }}
password: ${{ inputs.registry_token }}
- name: Check if revision exists in container registry
id: image_check
shell: bash
run: |
echo Checking whether Docker image "$IMAGE":"$TAG" exists
if docker manifest inspect "$IMAGE":"$TAG" > /dev/null; then
echo 'image_exists=true' >> $GITHUB_OUTPUT
echo "image exists!"
else
echo "image doesn't exist; Starting to Build and push image"
fi
env:
IMAGE: ${{ inputs.image }}
TAG: ${{ steps.tag_check.outputs.tag }}
- name: Check whether to push latest tag
if: ${{ steps.image_check.outputs.image_exists != 'true' || inputs.rebuild }}
id: latest_push
uses: actions/github-script@v7
env:
INPUT_PUSH_LATEST: ${{ steps.set_inputs.outputs.push_latest }}
INPUT_IMAGE: ${{ inputs.image }}
with:
script: |
if ( core.getInput('push_latest') == 'true' ) {
core.setOutput('latest_tag',core.getInput('image') + ':latest')
} else {
core.setOutput('latest_tag',core.getInput('image') + ':unstable')
}
- name: Set up QEMU
if: ${{ steps.image_check.outputs.image_exists != 'true' || inputs.rebuild }}
# QEMU emulation for the Arm portion of our multi-platform Docker image build. Intel Machines
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
if: ${{ steps.image_check.outputs.image_exists != 'true' || inputs.rebuild }}
# Required for multi-platform Docker image builds in GitHub Actions that use docker/build-push-action.
uses: docker/setup-buildx-action@v3
- name: Build image and push to GHCR
if: ${{ steps.image_check.outputs.image_exists != 'true' || inputs.rebuild }}
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ inputs.image }}:${{ steps.set_inputs.outputs.img_tag && inputs.img_tag || steps.tag_check.outputs.tag }}
${{ inputs.image }}:${{ steps.tag_check.outputs.tag }}
${{ steps.latest_push.outputs.latest_tag }}
file: ${{ inputs.dockerfile }}
build-args: ${{ inputs.build-args }}
platforms: ${{ inputs.platforms}}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
- name: Export GHCR.io resource
id: ghc_img_id
shell: bash
run: echo "ghc_img=${{ inputs.image }}:${{ steps.tag_check.outputs.tag }}" >> $GITHUB_OUTPUT