Skip to content

Deploy head

Deploy head #6

Workflow file for this run

name: "Deploy head"
on:
workflow_run:
workflows:
- CI
types:
- completed
branches:
- main
permissions:
contents: write
deployments: write
jobs:
check:
name: "Check skip"
runs-on: ubuntu-22.04
outputs:
is_newer: ${{ steps.step1.outputs.result }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check agains head
id: step1
shell: pwsh
run: |
git merge-base --is-ancestor refs/tags/head ${{ github.sha }}
echo "Result: $LASTEXITCODE"
if($LASTEXITCODE -eq 0) {
"result=1" | Out-File -Path $env:GITHUB_OUTPUT -Append
}
elseif($LASTEXITCODE -eq 1) {
"result=0" | Out-File -Path $env:GITHUB_OUTPUT -Append
exit 0
}
tag:
name: "Update tag"
runs-on: ubuntu-22.04
needs: check
if: needs.check.outputs.is_newer == 1
steps:
- uses: actions/checkout@v4
- name: Update head tag
run: |
git push --delete origin head
git tag head
git push origin head
assets:
name: "Upload assets"
runs-on: ubuntu-22.04
needs: check
if: needs.check.outputs.is_newer == 1
strategy:
fail-fast: false
matrix:
platform: [windows, linux]
include:
- platform: windows
arch: x86_64
release-ext: zip
release-type: application/zip
- platform: linux
arch: x86_64
release-ext: tar.gz
release-type: application/gzip
steps:
- name: Download build artifacts
uses: dawidd6/action-download-artifact@v6
with:
workflow: ci.yml
run_id: ${{ github.event.workflow_run.id }}
name: snail-server-${{ matrix.arch }}-${{ matrix.platform }}
path: bin
- name: Repack release asset (zip)
if: matrix.release-ext == 'zip'
run: |
mv ${{ github.workspace }}/bin/info.txt ${{ github.workspace }}/info.txt
zip snail-server-${{ matrix.arch }}-${{ matrix.platform }}.${{ matrix.release-ext }} bin/* info.txt
- name: Repack release asset (tar.gz)
if: matrix.release-ext == 'tar.gz'
run: |
mv ${{ github.workspace }}/bin/info.txt ${{ github.workspace }}/info.txt
tar -cvzf snail-server-${{ matrix.arch }}-${{ matrix.platform }}.${{ matrix.release-ext }} bin info.txt
- name: Upload release asset
shell: pwsh
run: |
$assetId = curl -L `
-H "Accept: application/vnd.github+json" `
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" `
-H "X-GitHub-Api-Version: 2022-11-28" `
https://api.github.com/repos/albertziegenhagel/snail-server/releases/110773624/assets | `
ConvertFrom-Json | `
Where-Object -Property name -Value "snail-server-${{ matrix.arch }}-${{ matrix.platform }}.${{ matrix.release-ext }}" -EQ | `
Select-Object -Expand id
if($assetId) {
curl -L `
-X DELETE `
-H "Accept: application/vnd.github+json" `
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"`
-H "X-GitHub-Api-Version: 2022-11-28" `
https://api.github.com/repos/albertziegenhagel/snail-server/releases/assets/$assetId
}
curl -i -X POST `
-H "Accept: application/vnd.github+json" `
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" `
-H "X-GitHub-Api-Version: 2022-11-28" `
-H "Content-Type: ${{ matrix.release-type }}" `
--data-binary "@snail-server-${{ matrix.arch }}-${{ matrix.platform }}.${{ matrix.release-ext }}" `
"https://uploads.github.com/repos/albertziegenhagel/snail-server/releases/110773624/assets?name=snail-server-${{ matrix.arch }}-${{ matrix.platform }}.${{ matrix.release-ext }}"
publish:
name: "Puplish"
runs-on: ubuntu-22.04
needs:
- tag
- assets
steps:
- uses: actions/checkout@v4
- name: Mark release as non-draft
run: |
curl -L -X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/albertziegenhagel/snail-server/releases/110773624" \
-d '{"draft":false}'