diff --git a/.github/workflows/github-release.yml b/.github/workflows/github-release.yml index 9019ce9399..9659fe23d0 100644 --- a/.github/workflows/github-release.yml +++ b/.github/workflows/github-release.yml @@ -3,14 +3,6 @@ name: Create GitHub Release on: workflow_dispatch: inputs: - version-name: - description: 'Version Name - E.g. "2024.11.1"' - required: true - type: string - version-number: - description: 'Version Number - E.g. "123456"' - required: true - type: string artifact-run-id: description: 'GitHub Action Run ID containing artifacts' required: true @@ -23,9 +15,6 @@ on: description: 'Mark as pre-release' type: boolean default: true - make-latest: - description: 'Set as the latest release' - type: boolean branch-protection-type: description: 'Branch protection type' type: choice @@ -78,51 +67,78 @@ jobs: esac echo "release_branch=$release_branch" >> $GITHUB_OUTPUT + - name: Get last release tag + id: get_last_tag + run: | + last_release_id=$(git tag -l --sort=-authordate | head -n 1) + echo "last_release_id=$last_release_id" >> $GITHUB_OUTPUT - name: Download artifacts env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} ARTIFACT_RUN_ID: ${{ inputs.artifact-run-id }} + run: ./Scripts/download-artifacts.sh $ARTIFACTS_PATH $ARTIFACT_RUN_ID + + - name: Parse version info + id: version_info run: | - gh run download $ARTIFACT_RUN_ID -D $ARTIFACTS_PATH - file_count=$(find $ARTIFACTS_PATH -type f | wc -l) - echo "Downloaded $file_count file(s)." - if [ "$file_count" -gt 0 ]; then - echo "Downloaded files:" - find $ARTIFACTS_PATH -type f - fi + unzip -o "$ARTIFACTS_PATH/version-info.zip" -d "tmp" + filepath="tmp/version-info/version_info.json" + version_name=$(jq -r '.version_name' "$filepath") + version_number=$(jq -r '.version_number' "$filepath") + echo "version_number=$version_number" >> $GITHUB_OUTPUT + echo "version_name=$version_name" >> $GITHUB_OUTPUT + rm -rf tmp - - name: Create Release + - name: Create GitHub Release id: create_release - uses: softprops/action-gh-release@e7a8f85e1c67a31e6ed99a94b41bd0b71bbee6b8 # v2.0.9 - with: - tag_name: "v${{ inputs.version-name }}" - name: "${{ inputs.version-name }} (${{ inputs.version-number }})" - prerelease: ${{ inputs.prerelease }} - draft: ${{ inputs.draft }} - make_latest: ${{ inputs.make-latest }} - target_commitish: ${{ steps.get_release_branch.outputs.release_branch }} - generate_release_notes: true - files: | - artifacts/**/* + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Create release with generated notes + url=$(gh release create "v${{ steps.version_info.outputs.version_name }}" \ + --title "${{ steps.version_info.outputs.version_name }} (${{ steps.version_info.outputs.version_number }})" \ + --target ${{ steps.get_release_branch.outputs.release_branch }} \ + --generate-notes \ + --notes-start-tag "${{ steps.get_last_tag.outputs.last_release_id }}" \ + --prerelease=${{ inputs.prerelease }} \ + --draft=${{ inputs.draft }} \ + $ARTIFACTS_PATH/*) + # Extract release tag from URL + release_id=$(echo "$url" | sed 's/.*\/tag\///') + echo "release_id=$release_id" >> $GITHUB_OUTPUT - name: Update Release Description + id: update_release_description env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - RELEASE_ID: ${{ steps.create_release.outputs.id }} - RELEASE_URL: ${{ steps.create_release.outputs.url }} + RELEASE_ID: ${{ steps.create_release.outputs.release_id }} ARTIFACT_RUN_ID: ${{ inputs.artifact-run-id }} run: | - # Get current release body - current_body=$(gh api /repos/${{ github.repository }}/releases/$RELEASE_ID --jq .body) - - # Append build source to the end + # Add builds source to the end of the release description + current_body=$(gh release view $RELEASE_ID --json body --jq .body) updated_body="${current_body} **Builds Source:** https://github.com/${{ github.repository }}/actions/runs/$ARTIFACT_RUN_ID" + new_url=$(gh release edit $RELEASE_ID --notes "$updated_body") - # Update release - gh api --method PATCH /repos/${{ github.repository }}/releases/$RELEASE_ID \ - -f body="$updated_body" + # draft release links change after editing + echo "release_url=$new_url" >> $GITHUB_OUTPUT - echo "# :rocket: Release ready at:" >> $GITHUB_STEP_SUMMARY + - name: Add Release Summary + env: + RELEASE_ID: ${{ steps.create_release.outputs.release_id }} + RELEASE_TAG: "v${{ steps.version_info.outputs.version_name }}" + RELEASE_BRANCH: ${{ steps.get_release_branch.outputs.release_branch }} + LAST_RELEASE_TAG: ${{ steps.get_last_tag.outputs.last_release_id }} + RELEASE_URL: ${{ steps.update_release_description.outputs.release_url }} + run: | + echo "# :fish_cake: Release ready at:" >> $GITHUB_STEP_SUMMARY echo "$RELEASE_URL" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo ":clipboard: Confirm that the defined GitHub Release options are correct:" >> $GITHUB_STEP_SUMMARY + echo " * :bookmark: New tag name: \`$RELEASE_TAG\`" >> $GITHUB_STEP_SUMMARY + echo " * :palm_tree: Target branch: \`$RELEASE_BRANCH\`" >> $GITHUB_STEP_SUMMARY + echo " * :ocean: Previous tag set in the description \"Full Changelog\" link: \`$LAST_RELEASE_TAG\`" >> $GITHUB_STEP_SUMMARY + echo " * :white_check_mark: Description has automated release notes and they match the commits in the release branch" >> $GITHUB_STEP_SUMMARY + echo "> [!NOTE]" >> $GITHUB_STEP_SUMMARY + echo "> Commits directly pushed to branches without a Pull Request won't appear in the automated release notes." >> $GITHUB_STEP_SUMMARY diff --git a/Scripts/download-artifacts.sh b/Scripts/download-artifacts.sh new file mode 100755 index 0000000000..c925220dc6 --- /dev/null +++ b/Scripts/download-artifacts.sh @@ -0,0 +1,59 @@ +#!/bin/bash +# Download Artifacts Script +# +# This script downloads build artifacts from a GitHub Actions run and processes them +# for the GitHub Release upload. It requires: +# - GitHub CLI (gh) to be installed and authenticated +# - Two arguments: +# 1. Target path where artifacts should be downloaded +# 2. GitHub Actions run ID to download artifacts from +# +# Example usage: +# ./download-artifacts.sh 2024.10.2 1234567890 +# +# The script will: +# 1. Create the target directory if it doesn't exist +# 2. Download all artifacts from the specified GitHub Actions run +# 3. Process the artifacts by zipping them with the same name as the folder + + +if [ $# -ne 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +TARGET_PATH="$1" +GITHUB_RUN_ID="$2" + +mkdir -p "$TARGET_PATH" + +cd "$TARGET_PATH" || exit 1 + +echo "🏃‍♂️💨 Downloading artifacts from GitHub run $GITHUB_RUN_ID..." +gh run download "$GITHUB_RUN_ID" + +# Output downloaded files +file_count=$(find . -type f | wc -l) +if [ "$file_count" -eq 0 ]; then + echo "👀 No files downloaded, processing skipped." + exit 0 +fi + +echo "🎉 Downloaded $file_count file(s)." +echo "Downloaded files:" +find . -type f + +# Process downloaded artifacts +echo "📦 Zipping artifacts" +for dir in */; do + if [ ! -d "$dir" ]; then + continue + fi + # Remove trailing slash from directory name + dirname=${dir%/} + basename=$(basename "$dirname") + zip -r -q "${basename}.zip" "$dirname" + echo " 🍣 Created $basename.zip" + rm -rf "$dirname" +done +echo "🍱 Finished zipping!"