nextcloudpi/.github/workflows/publish-image.yml
2022-08-16 21:41:50 +02:00

80 lines
1.9 KiB
YAML

name: "Publish Images"
on:
workflow_call:
inputs:
git_ref:
required: true
type: string
artifact_id:
required: true
type: string
artifact_file:
required: true
type: string
dry_run:
required: false
type: boolean
default: false
jobs:
publish:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
env:
VERSION: "${{ inputs.git_ref }}"
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: "${{ env.VERSION }}"
- name: "Download artifact"
uses: actions/download-artifact@v3
with:
name: ${{ inputs.artifact_id }}
path: artifacts
- name: "Publish artifact"
env:
IMG: "${{ inputs.artifact_file }}"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -ex
mkdir -p publish
mv artifacts/${{ inputs.artifact_file }} publish/
cd publish
asset="${IMG}"
[[ "$IMG" =~ .*".img" ]] && {
zip "${IMG%.img}.zip" "${IMG?}"
asset="${IMG%.img}.zip"
}
checksum="$(md5sum "$asset")"
echo "Artifact Checksum:
$checksum"
[[ "${{ inputs.dry_run }}" == "true" ]] && {
echo "Dry run only. Skipping release..."
exit 0
}
title="$(hub release show -f "%t" "${VERSION}")"
body="$(hub release show -f "%b" "${VERSION}")"
if ! [[ "$body" =~ .*'**Checksums:**'.* ]]
then
body="${body}
**Checksums:**
\`\`\`
\`\`\`"
fi
body="${body%$'\n```'*}
$checksum
\`\`\`"
hub release edit -a "${IMG?}" -m "${title?}" -m "$body" "${VERSION?}"