Skip to content

Commit

Permalink
Adjusts workflow summary formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
apbassett committed Oct 21, 2023
1 parent 9516522 commit 303fdee
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 43 deletions.
6 changes: 3 additions & 3 deletions .github/templates/version_summary.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## This workflow run was built with the following packages:
<br>

| Name | Version | Notes |
| :-- | :-- | :-- |
| amalgam | {amalgam-version} | {amalgam-notes} |
| Name | Version | Notes | Target SHA | URL |
| :-- | :-- | :-- | :-- | :-- |
| amalgam | {amalgam-version} | {amalgam-notes} | {amalgam-sha} | {amalgam-url} |
24 changes: 19 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,32 @@ jobs:
- name: Clean up dir
run: |
pwd
cp version.json amalgam/lib/version.json
cd amalgam/lib
pwd && ls
echo "---"
cd */*/ && ls
find . -name amalgam-mt -type f
fp=$(find . -name amalgam-mt -type f)
cp $fp ~/amalgam-mt
sed -i 's/dependencies/version/g' version.json
find . -type d -name lib -exec sh -c 'mv {}/* "$(dirname {})"' \;
- name: Set workflow run info
if: needs.get-dependency-details.outputs.build-date != ''
- name: Set amalgam version metadata
run: |
cd amalgam/lib
jq '.version |= . + {"amalgam_display_title": ${{ needs.get-dependency-details.outputs.build-title }}}' version.json > temp.json && mv temp.json version.json
jq '.version |= . + {"amalgam_build_date": ${{ needs.get-dependency-details.outputs.build-date }}}' version.json > temp.json && mv temp.json version.json
# Set the display title and build date info in version.json
if [[ "${{ needs.get-dependency-details.outputs.build-title }}" != "" ]]; then
jq '.version |= . + {"amalgam_display_title": ${{ needs.get-dependency-details.outputs.build-title }}}' version.json > temp.json && mv temp.json version.json
jq '.version |= . + {"amalgam_build_date": ${{ needs.get-dependency-details.outputs.build-date }}}' version.json > temp.json && mv temp.json version.json
# Replace the release version with the downloaded prerelease version
pr_version=$(~/amalgam-st --version | sed -n 's/Amalgam Version: \(.\)/\1/p')
echo "Found amalgam version: '$pr_version'"
jq --arg new_version "$pr_version" '.version.amalgam = $new_version' version.json > temp.json && mv temp.json version.json
rm ~/amalgam-mt
fi
jq '.version |= . + {"amalgam_sha": ${{ needs.get-dependency-details.outputs.head-sha }}}' version.json > temp.json && mv temp.json version.json
jq '.version |= . + {"amalgam_url": ${{ needs.get-dependency-details.outputs.url }}}' version.json > temp.json && mv temp.json version.json
cat version.json
- name: Build wheels
Expand Down
68 changes: 39 additions & 29 deletions .github/workflows/get-dependency-details.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ on:
build-title:
description: "The display title of the run (non-release)"
value: ${{ jobs.get-dependency-details.outputs.build-title }}
head-sha:
description: "The commit hash used for the workflow run"
value: ${{ jobs.get-dependency-details.outputs.head-sha }}
url:
description: "A URL pointing to the workflow run"
value: ${{ jobs.get-dependency-details.outputs.url }}

defaults:
run:
Expand All @@ -44,6 +50,8 @@ jobs:
run-id: ${{ steps.dependency.outputs.run-id }}
build-date: ${{ steps.dependency.outputs.build-date }}
build-title: ${{ steps.dependency.outputs.build-title }}
head-sha: ${{ steps.dependency.outputs.head-sha }}
url: ${{ steps.dependency.outputs.url }}
steps:
- uses: actions/checkout@v3

Expand All @@ -54,45 +62,47 @@ jobs:
run: |
echo "Parsing JSON payload: '${{ inputs.payload }}'..."
ID=""
if ! [[ -n "${{ inputs.payload }}" && $(echo '${{ inputs.payload }}' | jq 'has("${{ inputs.repo }}")') == true ]]; then
# Repo not specified in payload; check version.json
if [ "${{ inputs.skip-version-json-check }}" = true ]; then
echo "No JSON payload given with repo ${{ inputs.repo }}, and skip-version-json-check flag is set. Exiting."
exit 0
fi
echo "No JSON payload given with repo ${{ inputs.repo }}, using version.json"
ID=$(jq -r '.dependencies."${{ inputs.repo }}"' version.json)
echo "Searching for ${{ inputs.repo }} build id '$ID'..."
if gh release view --repo ${{ inputs.owner }}/${{ inputs.repo }} "$ID" > /dev/null 2>&1; then
echo "Found release build"
echo "run-type=$(echo "release")" >> $GITHUB_OUTPUT
elif gh run view --repo ${{ inputs.owner }}/${{ inputs.repo }} "$ID" > /dev/null 2>&1; then
echo "Found non-release build"
echo "run-type=$(echo "run")" >> $GITHUB_OUTPUT
else
echo "Build not found"
exit 1
fi
echo "Found build ID for ${{ inputs.repo }} in version.json: '$ID'"
else
ID=$(echo '${{ inputs.payload }}' | jq -r '."${{ inputs.repo }}"')
echo "${{ inputs.repo }} build id given: '$ID'"
echo "Payload contains build ID for ${{ inputs.repo }}: '$ID'"
fi
echo "Searching for ${{ inputs.repo }} build id '$ID'..."
if gh release view --repo ${{ inputs.owner }}/${{ inputs.repo }} "$ID" > /dev/null 2>&1; then
echo "Found release build"
echo "run-type=$(echo "release")" >> $GITHUB_OUTPUT
elif gh run view --repo ${{ inputs.owner }}/${{ inputs.repo }} "$ID" > /dev/null 2>&1; then
echo "Found non-release build"
echo "run-type=$(echo "run")" >> $GITHUB_OUTPUT
# Get the version and build date
build_date=$(gh run view --repo ${{ inputs.owner }}/${{ inputs.repo }} $ID --json createdAt | jq '.createdAt')
build_title=$(gh run view --repo ${{ inputs.owner }}/${{ inputs.repo }} $ID --json displayTitle | jq '.displayTitle')
echo "build-date=$(echo "$build_date")" >> $GITHUB_OUTPUT
echo "build-title=$(echo "$build_title")" >> $GITHUB_OUTPUT
else
echo "Build not found"
exit 1
fi
echo "Searching for ${{ inputs.repo }} build id '$ID'..."
if gh release view --repo ${{ inputs.owner }}/${{ inputs.repo }} "$ID" > /dev/null 2>&1; then
# Release
echo "Found release build"
echo "run-type=$(echo "release")" >> $GITHUB_OUTPUT
# Set metadata (sha, url)
head_sha=$(gh release view --repo ${{ inputs.owner }}/${{ inputs.repo }} $ID --json targetCommitish | jq '.targetCommitish')
url=$(gh release view --repo ${{ inputs.owner }}/${{ inputs.repo }} $ID --json url | jq '.url')
echo "head-sha=$(echo "$head_sha")" >> $GITHUB_OUTPUT
echo "url=$(echo "$url")" >> $GITHUB_OUTPUT
elif gh run view --repo ${{ inputs.owner }}/${{ inputs.repo }} "$ID" > /dev/null 2>&1; then
# Prerelease (workflow run)
echo "Found non-release build"
echo "run-type=$(echo "run")" >> $GITHUB_OUTPUT
# Set metadata (build date, title, sha, url)
build_date=$(gh run view --repo ${{ inputs.owner }}/${{ inputs.repo }} $ID --json createdAt | jq '.createdAt')
build_title=$(gh run view --repo ${{ inputs.owner }}/${{ inputs.repo }} $ID --json displayTitle | jq '.displayTitle')
head_sha=$(gh run view --repo ${{ inputs.owner }}/${{ inputs.repo }} $ID --json headSha | jq '.headSha')
url=$(gh run view --repo ${{ inputs.owner }}/${{ inputs.repo }} $ID --json url | jq '.url')
echo "build-date=$(echo "$build_date")" >> $GITHUB_OUTPUT
echo "build-title=$(echo "$build_title")" >> $GITHUB_OUTPUT
echo "head-sha=$(echo "$head_sha")" >> $GITHUB_OUTPUT
echo "url=$(echo "$url")" >> $GITHUB_OUTPUT
else
echo "Build not found"
exit 1
fi
echo "run-id=$(echo "$ID")" >> $GITHUB_OUTPUT
17 changes: 11 additions & 6 deletions .github/workflows/workflow-summary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,26 @@ jobs:
site_packages=$(python -m site --user-site)
# Get version, commit SHA, and workflow/release URL
amlg_version=$(jq -r '.version.amalgam' $site_packages/amalgam/lib/version.json)
amlg_sha=$(jq -r '.version."amalgam_sha"' $site_packages/amalgam/lib/version.json)
amlg_url=$(jq -r '.version."amalgam_url"' $site_packages/amalgam/lib/version.json)
if [[ $(cat $site_packages/amalgam/lib/version.json | jq '.version | has("amalgam_build_date")') == true ]]; then
# Get amalgam build title and date
# Get amalgam prerelease info (workflow run)
build_date=$(jq -r '.version."amalgam_build_date"' $site_packages/amalgam/lib/version.json)
build_date=$(python -c "from datetime import datetime; print(datetime.strptime('$build_date', '%Y-%m-%dT%H:%M:%SZ').strftime('%A, %B %d, %I:%M %p'))")
amlg_version=$(jq -r '.version."amalgam_display_title"' $site_packages/amalgam/lib/version.json)
amlg_notes=$(jq -r '.version."amalgam_display_title"' $site_packages/amalgam/lib/version.json)
amlg_version=$(echo "$amlg_version ($build_date)")
amlg_notes=$(echo "Prerelease version")
else
# Get amalgam release version
amlg_version=$(jq -r '.version.amalgam' $site_packages/amalgam/lib/version.json)
# Get amalgam release info
amlg_notes=$(echo "Release version specified in \`version.json\`")
fi
# amalgam notes
# Substitute info into version_summary.md
sed -i "s|{amalgam-version}|$amlg_version|g" ./.github/templates/version_summary.md
sed -i "s|{amalgam-notes}|$amlg_notes|g" ./.github/templates/version_summary.md
sed -i "s|{amalgam-sha}|$amlg_sha|g" ./.github/templates/version_summary.md
sed -i "s|{amalgam-url}|$amlg_url|g" ./.github/templates/version_summary.md
# Remove unecessary quotations from variable substitutions
sed -i "s|\"||g" ./.github/templates/version_summary.md
# Output filled template file to workflow summary
Expand Down

0 comments on commit 303fdee

Please sign in to comment.