Files
espurna/.github/workflows/release-preview.yml

108 lines
3.4 KiB
YAML

name: Preview release template
on:
workflow_dispatch:
jobs:
variables:
runs-on: ubuntu-latest
outputs:
build_date: ${{ steps.result.outputs.build_date }}
build_tag: ${{ steps.result.outputs.build_tag }}
last_rev: ${{ steps.result.outputs.last_rev }}
last_tag: ${{ steps.result.outputs.last_tag }}
steps:
- name: Prepare version variables
id: result
shell: bash
run: |
remote_last_tag() {
git ls-remote --tags --sort='version:refname' https://github.com/xoseperez/espurna.git 'github*' |\
cut -d'/' -f3 |\
grep -o -E '^github[0-9]{6}$' |\
sort -r |\
head -1
}
remote_revision() {
git ls-remote --exit-code --heads https://github.com/xoseperez/espurna.git refs/heads/$1 | cut -d$'\t' -f1
}
date=$(date +'%y%m%d')
echo "build_date=${date}" >> "$GITHUB_OUTPUT"
tag="github${date}"
echo "build_tag=${tag}" >> "$GITHUB_OUTPUT"
dev=$(remote_revision dev)
echo "last_rev=${dev}" >> "$GITHUB_OUTPUT"
last=$(remote_last_tag)
echo "last_tag=${last}" >> "$GITHUB_OUTPUT"
build:
needs: variables
runs-on: ubuntu-latest
strategy:
matrix:
id: [0, 1, 2, 3]
steps:
- uses: actions/checkout@v4
with:
path: espurna
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Build
run: |
echo "build_date=" ${{ needs.variables.outputs.build_date }}
echo "build_tag=" ${{ needs.variables.outputs.build_tag }}
echo "last_rev=" ${{ needs.variables.outputs.last_rev }}
echo "last_tag=" ${{ needs.variables.outputs.last_tag }}
pushd espurna/code
# github actions allow empty / non-existent output names. check manually
build_date=${{ needs.variables.outputs.build_date }}
test -n "$build_date" || exit 2
# each 'id' in matrix only builds every Nth environment
./scripts/generate_release_sh.py \
--ignore secure-client \
--destination ${GITHUB_WORKSPACE}/build \
--builder-id ${{ strategy.job-index }} \
--builder-total ${{ strategy.job-total }} \
--suffix github${build_date}
popd
release:
needs: [variables, build]
runs-on: ubuntu-latest
steps:
- name: Fetch release template
run: |
curl \
-H "Authorization: Bearer ${{ github.token }}" \
-H "Accept: application/vnd.github.VERSION.raw" \
-o release_template.md \
https://api.github.com/repos/xoseperez/espurna/contents/.github/release_template.md
- name: Render release template
run: |
echo "build_date=" ${{ needs.variables.outputs.build_date }}
echo "build_tag=" ${{ needs.variables.outputs.build_tag }}
echo "last_rev=" ${{ needs.variables.outputs.last_rev }}
echo "last_tag=" ${{ needs.variables.outputs.last_tag }}
sed \
-i \
-e 's/\$\$BUILD_TAG\$\$/'${{ needs.variables.outputs.build_tag }}'/g' \
-e 's/\$\$LAST_TAG\$\$/'${{ needs.variables.outputs.last_tag }}'/g' \
release_template.md
- uses: actions/upload-artifact@v4
with:
name: release_template.md
path: release_template.md