forked from stellar/quickstart
-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (71 loc) · 3 KB
/
manifest.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
on:
workflow_call:
secrets:
DOCKERHUB_USERNAME:
required: false
DOCKERHUB_TOKEN:
required: false
inputs:
tag:
description: 'Tag to use as the manifest list image name'
type: 'string'
required: true
tag-alias:
description: 'Tag to alias to the tag of the manifest, e.g. "latest"'
type: 'string'
required: true
images:
description: 'Space separated list of images to include in the manifest list'
type: 'string'
required: true
outputs:
image:
description: 'Image pushed as a result of this build'
value: ${{ jobs.build.outputs.image }}
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
IMAGE: ${{ format('{0}/{1}:{2}', secrets.DOCKERHUB_TOKEN && 'docker.io' || 'ghcr.io', github.repository, github.event_name == 'pull_request' && format('pr{0}-{1}', github.event.pull_request.number, inputs.tag) || inputs.tag) }}
IMAGE_ALIAS: ${{ format('{0}/{1}:{2}', secrets.DOCKERHUB_TOKEN && 'docker.io' || 'ghcr.io', github.repository, github.event_name == 'pull_request' && format('pr{0}-{1}', github.event.pull_request.number, inputs.tag-alias) || inputs.tag-alias) }}
REGISTRY: ${{ secrets.DOCKERHUB_TOKEN && 'docker.io' || 'ghcr.io' }}
jobs:
push:
if: ${{ github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }}
permissions:
packages: write
statuses: write
runs-on: ubuntu-latest
steps:
- id: image_parts
run: |
IMAGE_TAGLESS=$(echo ${{ env.IMAGE }} | cut -d':' -f1)
IMAGE_REPO=$(echo $IMAGE_TAGLESS | cut -d'/' -f2,3)
IMAGE_TAG=$(echo ${{ env.IMAGE }} | cut -d':' -f2)
echo "::set-output name=repo::$IMAGE_REPO"
echo "::set-output name=tag::$IMAGE_TAG"
- uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKERHUB_USERNAME || github.actor }}
password: ${{ secrets.DOCKERHUB_TOKEN || github.token }}
- run: echo "IMAGE_URL=https://${{ env.IMAGE }}" >> $GITHUB_ENV
- if: ${{ env.REGISTRY == 'docker.io' }}
run: |
echo "IMAGE_URL=https://hub.docker.com/r/${{ steps.image_parts.outputs.repo }}/tags?name=${{ steps.image_parts.outputs.tag }}" >> $GITHUB_ENV
- run: |
docker manifest create ${{ env.IMAGE }} ${{ inputs.images }}
- run: |
docker manifest push ${{ env.IMAGE }}
- run: |
docker buildx imagetools create -t ${{ env.IMAGE_ALIAS }} ${{ env.IMAGE }}
- uses: actions/github-script@v5
with:
script: |
github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: '${{ env.HEAD_SHA }}',
state: 'success',
context: `${{ env.IMAGE }}`,
target_url: '${{ env.IMAGE_URL }}',
description: 'Available',
});