Skip to content

Copy assets to the new release #4

Copy assets to the new release

Copy assets to the new release #4

name: Copy assets to the new release
on:
release:
types: published
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
release:
name: Copy assets to the new release
runs-on: ubuntu-latest
permissions:
contents: write # to upload assets to releases
attestations: write # to upload assets attestation for build provenance
id-token: write # grant additional permission to attestation action to mint the OIDC token permission
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download assets
run: |
LATEST="$(git describe --tags --abbrev=0)"
PREVIOUS="$(git describe --tags --abbrev=0 "$LATEST"^)"
mkdir release-assets && cd release-assets
gh release download "$PREVIOUS"
- name: Check for generated files
working-directory: release-assets
id: check-files
run: |
echo "zip_exists=$(if [[ $(find language_archives -name '*.zip' | wc -l) -gt 0 ]]; then echo true; else echo false; fi)" >> $GITHUB_ENV
echo "pdf_exists=$(if [[ $(find scripts/pdf -name '*.pdf' | wc -l) -gt 0 ]]; then echo true; else echo false; fi)" >> $GITHUB_ENV
echo "checksums_exists=$(if [[ -f 'tldr.sha256sums' ]]; then echo true; else echo false; fi)" >> $GITHUB_ENV
- name: Construct subject-path for attest action
working-directory: release-assets
id: construct-subject-path
run: |
subject_path=""
if [[ ${{ env.zip_exists }} == 'true' ]]; then
zip_files=$(find language_archives -name '*.zip' -printf '%p,')
subject_path+="${zip_files::-1}"
fi
if [[ ${{ env.pdf_exists }} == 'true' ]]; then
if [[ -n $subject_path ]]; then subject_path+=","; fi
pdf_files=$(find scripts/pdf -name '*.pdf' -printf '%p,')
subject_path+="${pdf_files::-1}"
fi
if [[ ${{ env.checksums_exists }} == 'true' ]]; then
if [[ -n $subject_path ]]; then subject_path+=","; fi
subject_path+='tldr.sha256sums'
fi
echo "subject_path=$subject_path" >> $GITHUB_ENV
- name: Attest copied assets
uses: actions/attest-build-provenance@v1
with:
subject-path: ${{ env.subject_path }}
- name: Upload assets
working-directory: release-assets
run: gh release upload "$LATEST" -- *