From 4bbe8b56b4755aea1f3be896259580dd731369ee Mon Sep 17 00:00:00 2001 From: apbassett <43486400+apbassett@users.noreply.github.com> Date: Sat, 21 Oct 2023 16:21:10 -0400 Subject: [PATCH] Adjusts workflow summary formatting --- .github/templates/version_summary.md | 6 +- .github/workflows/build.yml | 31 +++++++-- .github/workflows/get-dependency-details.yml | 68 +++++++++++--------- .github/workflows/workflow-summary.yml | 17 +++-- 4 files changed, 78 insertions(+), 44 deletions(-) diff --git a/.github/templates/version_summary.md b/.github/templates/version_summary.md index 748d281..925dd8f 100644 --- a/.github/templates/version_summary.md +++ b/.github/templates/version_summary.md @@ -1,6 +1,6 @@ ## This workflow run was built with the following packages:
-| Name | Version | Notes | -| :-- | :-- | :-- | -| amalgam | {amalgam-version} | {amalgam-notes} | \ No newline at end of file +| Name | Version | Notes | Target SHA | URL | +| :-- | :-- | :-- | :-- | :-- | +| amalgam | {amalgam-version} | {amalgam-notes} | {amalgam-sha} | {amalgam-url} | \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d83b39f..622764c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -115,20 +115,39 @@ jobs: # Needed because release/non-release downloads are different structure cd amalgam/lib/windows/amd64 && if [ ! -f *.tar.gz ]; then mv */*.tar.gz ./; fi && tar -xvzf *.tar.gz - - name: Clean up dir + - name: Clean up dir (plat-specific) + if: matrix.plat != 'any' run: | - pwd cp version.json amalgam/lib/version.json cd amalgam/lib 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: Clean up dir (all plats) + if: matrix.plat == 'any' + run: | + cp version.json amalgam/lib/version.json + cd amalgam/lib + cp linux/amd64/bin/amalgam-mt ~/amalgam-mt + sed -i 's/dependencies/version/g' version.json + find . -type d -name lib -exec sh -c 'mv {}/* "$(dirname {})"' \; + + - name: Set amalgam version metadata + if: matrix.plat == 'any' 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 diff --git a/.github/workflows/get-dependency-details.yml b/.github/workflows/get-dependency-details.yml index 384f7f1..0cd282b 100644 --- a/.github/workflows/get-dependency-details.yml +++ b/.github/workflows/get-dependency-details.yml @@ -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: @@ -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 @@ -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 \ No newline at end of file diff --git a/.github/workflows/workflow-summary.yml b/.github/workflows/workflow-summary.yml index a03edd9..6619a0c 100644 --- a/.github/workflows/workflow-summary.yml +++ b/.github/workflows/workflow-summary.yml @@ -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