-
Notifications
You must be signed in to change notification settings - Fork 1
173 lines (148 loc) · 5.31 KB
/
docker-publish.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
name: docker-publish
on:
workflow_dispatch:
inputs:
tag:
description: 'Lynx release tag'
required: false
default: ''
run_number:
description: 'Lynx release.yml workflow run number. If not empty, artifact is downloaded from this workflow'
required: false
default: ''
version:
description: "Lynx version. Only useful when providing a 'run_number'"
required: false
default: ''
env:
LYNX_RELEASE_TAG: ${{ github.event.inputs.tag }}
LYNX_RELEASE_VERSION: ${{ github.event.inputs.version }}
REGISTRY: ghcr.io
ARM_RID: linux-arm64
AMD_RID: linux-x64
jobs:
download-lynx-artifact-from-release:
if: github.event.inputs.run_number == ''
runs-on: ubuntu-latest
strategy:
matrix:
rid: ["linux-arm64", "linux-x64"]
fail-fast: true
steps:
- name: Set LYNX_RELEASE_VERSION env var
shell: pwsh
run: |
echo "LYNX_RELEASE_VERSION=$("${{ env.LYNX_RELEASE_TAG }}".Replace('v', ''))" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
- name: Download ${{ matrix.rid }} executable
shell: pwsh
run: |
function Download-Asset{
param(
[Parameter(Mandatory=$true)]
[string] $tag,
[Parameter(Mandatory=$true)]
[string] $version,
[Parameter(Mandatory=$true)]
[string] $rid
)
$release = Invoke-RestMethod -Uri https://api.github.com/repos/lynx-chess/Lynx/releases/tags/$tag -Headers @{'Accept' = 'application/vnd.github.v3+json'}
$url = $release.assets | Where { $_.name -eq "Lynx-$version-$rid.zip" } | Select -ExpandProperty url
Invoke-RestMethod $url -Headers @{'Accept' = 'application/octet-stream'} -OutFile artifacts/lynx-$rid.zip
Expand-Archive artifacts/lynx-$rid.zip -DestinationPath artifacts/lynx-$rid/
rm artifacts/lynx-$rid.zip
}
New-Item -ItemType Directory -Force -Path artifacts/
Download-Asset -tag "${{ env.LYNX_RELEASE_TAG }}" -version "${{ env.LYNX_RELEASE_VERSION }}" -rid "${{ matrix.rid }}"
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: lynx-${{ matrix.rid }}
path: |
artifacts/lynx-${{ matrix.rid }}/
if-no-files-found: error
download-lynx-artifact-from-workflow-run:
name: Download Lynx artifacts from a Lynx release workflow run
if: github.event.inputs.run_number != ''
runs-on: ubuntu-latest
strategy:
matrix:
rid: ["linux-arm64", "linux-x64"]
fail-fast: true
steps:
- name: Download artifact from workflow run
uses: dawidd6/action-download-artifact@v2
with:
github_token: ${{secrets.GITHUB_TOKEN}}
repo: lynx-chess/Lynx
workflow: release.yml
workflow_conclusion: success
run_number: ${{ github.event.inputs.run_number }}
name: Lynx-${{ env.LYNX_RELEASE_VERSION }}-${{ matrix.rid }}
path: artifacts/lynx-${{ matrix.rid }}
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: lynx-${{ matrix.rid }}
path: |
artifacts/lynx-${{ matrix.rid }}/
if-no-files-found: error
publish-docker-images:
name: Publish Docker images
needs: [download-lynx-artifact-from-release, download-lynx-artifact-from-workflow-run]
if: always()
runs-on: ubuntu-latest
strategy:
matrix:
docker-target: [lynx, lynx-bot]
fail-fast: false
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
path: artifacts/
- name: Set LYNX_RELEASE_TAG env var
if: env.LYNX_RELEASE_TAG == ''
shell: pwsh
run: |
echo "LYNX_RELEASE_TAG=$("${{ github.event.inputs.version }}".Replace('v', ''))" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
- name: Amend LYNX_RELEASE_TAG env var
if: env.LYNX_RELEASE_TAG != ''
shell: pwsh
run: |
echo "LYNX_RELEASE_TAG=$("${{ env.LYNX_RELEASE_TAG }}".Replace('v', ''))" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
- name: Docker login
run: echo "${{ secrets.DOCKER_REGISTRY_TOKEN }}" | docker login ${{ env.REGISTRY }} -u ${{ github.actor }} --password-stdin
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
target: ${{ matrix.docker-target }}
build-args: |
ARM_ARTIFACT_PATH=artifacts/lynx-${{ env.ARM_RID }}/
AMD_ARTIFACT_PATH=artifacts/lynx-${{ env.AMD_RID }}/
platforms: |
linux/amd64
linux/arm64
tags: |
${{ env.REGISTRY }}/lynx-chess/${{ matrix.docker-target }}:${{ env.LYNX_RELEASE_TAG}}
push: true
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
cleanup:
name: Cleanup
needs: [publish-docker-images]
if: always()
runs-on: ubuntu-latest
steps:
- name: Deleting ${{ matrix.artifact }}
uses: geekyeggo/delete-artifact@v1
with:
name: |
lynx-${{ env.ARM_RID }}
lynx-${{ env.AMD_RID }}
failOnError: false