Skip to content

Commit

Permalink
fix: publish
Browse files Browse the repository at this point in the history
  • Loading branch information
Skylar Simoncelli committed Oct 3, 2024
1 parent 69c57a9 commit 98b1871
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/actions/images/build-and-publish-ghcr/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ runs:

- name: Build Docker Image
run: |
docker build -t substrate-node:latest
docker build -t substrate-node:latest .
shell: bash

- name: Login to GitHub Container Registry
Expand Down
54 changes: 54 additions & 0 deletions .github/actions/release/create-draft-release/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,58 @@ runs:
--data-binary @"$artifact" \
"https://uploads.github.com/repos/${{ github.repository }}/releases/$release_id/assets?name=$(basename $artifact)"
done
shell: bash

- name: Modify Release Notes
id: modify_release_notes
run: |
release_id="${{ steps.create_release.outputs.release_id }}"
if [ -z "$release_id" ]; then
release_id="${{ steps.check_release.outputs.release_id }}"
fi
# Fetch the existing release notes
release_data=$(curl -s -H "Authorization: token ${{ env.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/$release_id")
# Extract the release body
release_body=$(echo "$release_data" | jq -r .body)
# Process the release notes
# Rename "## What's Changed" to "## Commits in this Release"
# Limit the entries under this section to the first 10
# Wrap the rest under a collapsible "Show more" section
# Extract sections
before_whats_changed=$(echo "$release_body" | sed -n '1,/## What.s Changed/p' | sed '$d')
whats_changed_section=$(echo "$release_body" | sed -n '/## What.s Changed/,/^## /p' | sed '1d;$d')
after_whats_changed=$(echo "$release_body" | sed -n '/^## New Contributors/,$p')
# Limit "What's Changed" to first 10 entries
IFS=$'\n' read -rd '' -a entries <<<"$whats_changed_section"
total_entries=${#entries[@]}
if [ "$total_entries" -gt 10 ]; then
first_10_entries="${entries[@]:0:10}"
remaining_entries="${entries[@]:10}"
remaining_entries_str=$(printf "%s\n" "${remaining_entries[@]}")
details_section="\n<details>\n<summary>Show more</summary>\n\n$remaining_entries_str\n</details>\n"
else
first_10_entries="${entries[@]}"
details_section=""
fi
# Rename "What's Changed" to "Commits in this Release"
modified_whats_changed="## Commits in this Release\n\n"
modified_whats_changed+=$(printf "%s\n" "${first_10_entries[@]}")
modified_whats_changed+="$details_section"
# Combine all parts
modified_release_body="$before_whats_changed\n$modified_whats_changed\n$after_whats_changed"
# Update the release with modified release notes
curl -s -X PATCH -H "Authorization: token ${{ env.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d '{"body": "'"${modified_release_body//\"/\\\"}"'"}' \
"https://api.github.com/repos/${{ github.repository }}/releases/$release_id"
shell: bash
37 changes: 26 additions & 11 deletions .github/actions/release/publish-draft-release/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,48 @@ inputs:
description: "Tag for the release"
required: true

outputs: {}
outputs:
release_exists:
description: "Whether the release exists"
value: ${{ steps.check_release.outputs.release_exists }}
release_id:
description: "ID of the release"
value: ${{ steps.check_release.outputs.release_id }}

runs:
using: "composite"
steps:
- name: Check if release exists
id: check_release
run: |
set -e
tag="${{ inputs.tag }}"
release_response=$(curl -s -H "Authorization: token ${{ env.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/tags/$tag")
release_response=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/releases/tags/$tag")
if echo "$release_response" | grep -q '"message": "Not Found"'; then
echo "release_exists=false" >> $GITHUB_ENV
echo "::set-output name=release_exists::false"
echo "release_exists=false" >> "$GITHUB_OUTPUT"
echo "release_id=" >> "$GITHUB_OUTPUT"
else
echo "release_exists=true" >> $GITHUB_ENV
echo "::set-output name=release_exists::true"
echo "release_id=$(echo $release_response | jq -r .id)" >> $GITHUB_ENV
echo "::set-output name=release_id::$(echo $release_response | jq -r .id)"
echo "release_exists=true" >> "$GITHUB_OUTPUT"
release_id=$(echo "$release_response" | jq -r .id)
echo "release_id=$release_id" >> "$GITHUB_OUTPUT"
fi
shell: bash

- name: Publish release
if: ${{ steps.check_release.outputs.release_exists == 'true' }}
run: |
set -e
release_id="${{ steps.check_release.outputs.release_id }}"
curl -s -X PATCH -H "Authorization: token ${{ env.GITHUB_TOKEN }}" \
response=$(curl -s -X PATCH -H "Authorization: token $GITHUB_TOKEN" \
-d '{"draft": false}' \
"https://api.github.com/repos/${{ github.repository }}/releases/$release_id"
"https://api.github.com/repos/${{ github.repository }}/releases/$release_id")
echo "Response: $response"
if echo "$response" | jq -e '.id' >/dev/null; then
echo "Release updated successfully"
else
echo "Failed to update release"
exit 1
fi
shell: bash

0 comments on commit 98b1871

Please sign in to comment.