docker-publish #160
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |