Skip to content

Prepare version release #60

Prepare version release

Prepare version release #60

env:
RELEASE_META: |
{
"win_release": {
"x64": {
"os": "Windows",
"arch": "x86_64",
"installer_url": "",
"portable_url": ""
},
"arm64": {
"os": "Windows",
"arch": "ARM64",
"installer_url": "",
"portable_url": ""
}
},
"mac_release": {
"universal": {
"os": "MacOS X",
"arch": "Universal (x64 & ARM64)",
"image_url": ""
}
},
"lin_release": {
"x64": {
"os": "Linux",
"arch": "x64",
"image_url": "",
"portable_url": ""
},
"arm64": {
"os": "Linux",
"arch": "ARM64",
"image_url": "",
"portable_url": ""
}
}
}
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
name: Prepare version release
on:
workflow_dispatch:
inputs:
RUN_IDS_TO_USE:
description: 'Existing RUN IDs to use instead of a fresh build'
required: false
default: ''
type: string
CODE_SIGN:
description: 'Sign artifacts'
required: true
type: boolean
default: true
TEST_RUN:
description: 'Test run (-test suffix for release)'
required: false
type: boolean
default: false
DEBUG:
description: 'Enable workflow debug messages'
required: false
type: boolean
default: false
jobs:
build:
runs-on: ubuntu-22.04
steps:
- name: Clone GH scripts
uses: actions/checkout@v6
with:
repository: pawelsalawa/gh-action-scripts
ref: main
- name: Set environment variables for scripts
run: |
echo "REPO=${{ github.repository }}" >> $GITHUB_ENV
echo "TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
chmod +x scripts/*.sh
echo "SCRIPTS=$(pwd)/scripts" >> $GITHUB_ENV
echo "DEBUG=${{ inputs.DEBUG }}" >> $GITHUB_ENV
- name: Trigger binary build workflows
shell: bash
if: inputs.RUN_IDS_TO_USE == ''
run: |
WORKFLOWS=()
for key in $(echo "$RELEASE_META" | jq -r 'keys[]')
do
WORKFLOWS+=("$key.yml")
done
echo "Workflows to trigger: ${WORKFLOWS[@]}"
echo "WORKFLOWS=${WORKFLOWS[@]}" >> $GITHUB_ENV
run_ids=()
inputs="{}"
if [ "${DEBUG}" = "true" ]
then
inputs=$(echo $inputs | jq -c '.DEBUG = "true"')
fi
if [ "${CODE_SIGN}" = "true" ]
then
inputs=$(echo $inputs | jq -c '.CODE_SIGN = "true"')
fi
for wname in ${WORKFLOWS[@]}
do
run_id=$($SCRIPTS/run_workflow.sh $wname "$inputs" "${{ github.ref_name }}")
run_ids+=( $run_id )
done
echo "CHILD_IDS=${run_ids[@]}" >> $GITHUB_ENV
- name: Wait for workflows to complete
shell: bash
if: inputs.RUN_IDS_TO_USE == ''
run: |
echo "Workflow IDs to wait for: $CHILD_IDS"
success=0
for runid in $CHILD_IDS
do
success=$($SCRIPTS/wait_for_run.sh $runid 50)
if [ $success -eq 1 ]
then
echo "Child build $runid finished successfully."
else
echo "Child build $runid failed."
exit 1
fi
done
echo "All child workflows finished successfully."
- name: Determin final RUN IDs
shell: bash
run: |
if [ "${{ inputs.RUN_IDS_TO_USE }}" != "" ]
then
CHILD_IDS="${{ inputs.RUN_IDS_TO_USE }}"
echo "CHILD_IDS=$CHILD_IDS" >> $GITHUB_ENV
fi
- name: Get Letos version
shell: bash
run: |
ref="${{ env.BRANCH_NAME }}"
url="https://raw.githubusercontent.com/pawelsalawa/letos/refs/heads/$ref/Letos/core/letos.cpp"
int_ver=$(curl -s -L $url | grep "static const int letosVersion" | grep -o "[0-9]*")
LETOS_VERSION=$($SCRIPTS/convert_int_ver.sh $int_ver)
echo "LETOS_VERSION=$LETOS_VERSION" >> $GITHUB_ENV
- name: Download artifacts
shell: bash
run: |
mkdir assets
cd assets
for runid in ${{ env.CHILD_IDS }}
do
resp=$($SCRIPTS/query_run.sh $runid)
workflow_file=$(basename $(echo "$resp" | jq -r '.path'))
REL_NAME="${workflow_file%.*}"
mkdir $REL_NAME
cd $REL_NAME
$SCRIPTS/download_artifacts.sh $runid
rm -f unsigned*
cd ..
done
echo "Downloaded files:"
find .
- name: Create a draft release
shell: bash
working-directory: assets
run: |
tag_name="$LETOS_VERSION"
rel_name="$LETOS_VERSION release"
if [ "${{ inputs.TEST_RUN }}" == "true" ]
then
tag_name="${tag_name}-test"
rel_name="${rel_name}-test"
fi
echo "TAG_NAME=$tag_name" >> $GITHUB_ENV
releaseid=$($SCRIPTS/create_draft_release.sh "$tag_name" "$BRANCH_NAME" "$rel_name" "")
echo "RELEASE_ID: $releaseid"
echo "RELEASE_ID=$releaseid" >> $GITHUB_ENV
- name: Upload assets
shell: bash
working-directory: assets
run: |
NEW_META=$(echo "$RELEASE_META" | jq -c '.')
for dir in *
do
cd $dir
for file in *
do
# Adding uniq_ prefix, cause inner zip file may have exactly same name
uniq_nm=uniq_$file
mv $file $uniq_nm
unzip $uniq_nm
file="$(unzip -Z1 $uniq_nm)"
rm -f $uniq_nm
if [[ "$file" == *"installer"* || "$file" == *"setup"* ]]; then
url_type=installer_url
elif [[ "$file" == *"AppImage" || "$file" == *"dmg" ]]; then
url_type=image_url
else
url_type=portable_url
fi
if [[ "$file" == *x64* || "$file" == *x86_64* ]]; then
arch="x64"
elif [[ "$file" == *arm64* || "$file" == *aarch64* ]]; then
arch="arm64"
elif [[ "$file" == *universal* ]]; then
arch="universal"
else
echo "Unexpected archictecture for: $file"
exit 1
fi
echo "Uploading $file..."
url=$($SCRIPTS/upload_artifact.sh $RELEASE_ID "$file")
url=$(echo $url | sed -E "s/untagged-[^\/]*/$LETOS_VERSION/")
echo "Download url for $file is: $url"
NEW_META=$(
echo "$NEW_META" | \
jq -c \
--arg dir "$dir" \
--arg url "$url" \
--arg arch "$arch" \
--arg url_type "$url_type" \
'.[$dir][$arch][$url_type] = $url'
)
done
cd ..
done
echo "META after uploads:"
echo "$NEW_META" | jq '.'
echo "RELEASE_META=$NEW_META" >> $GITHUB_ENV
- name: Update release description
shell: bash
working-directory: assets
run: |
body_lines=()
body_lines+=("| File name | Platform | Architecture | Package type |")
body_lines+=("| --- | --- | --- | --- |")
for dir in *
do
cd $dir
for file in *
do
if [[ "$file" == *x64* || "$file" == *x86_64* ]]; then
arch="x64"
elif [[ "$file" == *arm64* || "$file" == *aarch64* ]]; then
arch="arm64"
elif [[ "$file" == *universal* ]]; then
arch="universal"
else
echo "Unexpected archictecture for: $file"
exit 1
fi
os=$(echo $RELEASE_META | jq -r --arg dir $dir --arg arch "$arch" '.[$dir][$arch].os')
archstr=$(echo $RELEASE_META | jq -r --arg dir $dir --arg arch "$arch" '.[$dir][$arch].arch')
portable_url=$(echo $RELEASE_META | jq -r --arg dir $dir --arg arch "$arch" '.[$dir][$arch].portable_url')
installer_url=$(echo $RELEASE_META | jq -r --arg dir $dir --arg arch "$arch" '.[$dir][$arch].installer_url')
image_url=$(echo $RELEASE_META | jq -r --arg dir $dir --arg arch "$arch" '.[$dir][$arch].image_url')
if [[ "$file" == *"installer"* || "$file" == *"setup"* ]]; then
url=$installer_url
type="Installer"
elif [[ "$file" == *"AppImage" ]]; then
url=$image_url
type="AppImage"
elif [[ "$file" == *"dmg" ]]; then
url=$image_url
type="DMG Image"
else
url=$portable_url
type="Portable"
fi
body_lines+=("| [$file]($url) | $os | $archstr | $type |")
done
cd ..
done
body_lines+=("")
body_lines+=("## Checksums")
body_lines+=("| File name | SHA256 checksum |")
body_lines+=("| --- | --- |")
for dir in *
do
cd $dir
for file in *
do
checksum=$(sha256sum $file | cut -d ' ' -f 1)
body_lines+=("| [$file]($url) | \`$checksum\` |")
done
cd ..
done
body=$(printf "%s\n" "${body_lines[@]}")
$SCRIPTS/update_release_body.sh $RELEASE_ID "$TAG_NAME" "$body" >/dev/null