Upload release #9
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: Upload release | |
defaults: | |
run: | |
shell: bash | |
on: | |
workflow_dispatch: | |
inputs: | |
command: | |
description: 'Run custom command before building' | |
required: false | |
type: string | |
run_id: | |
description: 'Run id contains artifact being uploaded' | |
required: true | |
type: string | |
tag_name: | |
description: 'Release tag name' | |
required: false | |
type: string | |
jobs: | |
release: | |
name: Upload releases | |
runs-on: ubuntu-latest | |
steps: | |
- name: Update package lists and install jq | |
run: | | |
sudo apt update | |
sudo apt install jq -y | |
- name: Init variable | |
run: | | |
curl -L \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer ${{ secrets.GH_ACTION_TOKEN }}" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runs/${{ github.event.inputs.run_id }}/artifacts > artifacts.json | |
cat artifacts.json | |
- name: Download artifacts | |
run: | | |
desired_prefix="developer.mozilla.org_" | |
archive_download_urls=$(cat artifacts.json | jq -r --arg desired_prefix "$desired_prefix" '.artifacts[] | select(.name | startswith($desired_prefix)).archive_download_url') | |
echo $archive_download_urls | |
mkdir -p download | |
pushd download | |
for url in $archive_download_urls; do | |
auth_header="Authorization: Bearer ${{ secrets.GH_ACTION_TOKEN }}" | |
# Make the initial request with the Authorization header and capture the headers | |
response_headers=$(curl -s -I -L --header "$auth_header" "$url") | |
# Look for a Location header in case of a redirect | |
redirect_url=$(echo "$response_headers" | grep -i Location: | tail -n1 | sed -e 's/Location: //I' | tr -d '\r') | |
# Check if a redirect URL was found | |
if [ -n "$redirect_url" ]; then | |
echo "Redirect URL found: $redirect_url" | |
# Make a new request to the redirect URL without the Authorization header | |
curl -L "$redirect_url" --remote-header-name -O | |
else | |
echo "No redirect URL found, downloading directly." | |
# If no redirect was found, download the file directly with the Authorization header | |
curl -L --header "$auth_header" "$url" --remote-header-name -O | |
fi | |
done | |
mkdir -p ../release | |
for zip_file in $(ls); do | |
unzip "$zip_file" -d ../release | |
done | |
popd | |
- name: Running custom command | |
if: ${{ github.event.inputs.command != '' }} | |
continue-on-error: true | |
run: ${{ github.event.inputs.command }} | |
- name: Empty check | |
run: | | |
[ ! -z "$(ls -A release)" ] | |
- name: Collect hash | |
run: | | |
pushd release | |
sha256sum * > ../sha256sum.txt | |
sha1sum * > ../sha1sum.txt | |
popd | |
echo -e '\n\nsha256sum\n-----------\n```\n' > release.txt | |
cat sha256sum.txt >> release.txt | |
echo -e '\n```\n\nsha1sum\n-----------\n```\n' >> release.txt | |
cat sha1sum.txt >> release.txt | |
echo -e '\n```\n' >> release.txt | |
cat release.txt | |
- name: Release | |
uses: softprops/action-gh-release@v1 | |
if: ${{ github.event.inputs.tag_name != '' }} | |
with: | |
draft: true | |
prerelease: true | |
tag_name: ${{ github.event.inputs.tag_name }} | |
fail_on_unmatched_files: true | |
body_path: release.txt | |
files: release/* | |