Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

17808: Adds workflow summary, misc. workflow changes #21

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/templates/version_summary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## This workflow run was built with the following packages:
<br>

| Name | Version | Notes |
| :-- | :-- | :-- |
| amalgam | {amalgam-version} | {amalgam-notes} |
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
payload:
required: false
type: string
build-type:
required: false
type: string

jobs:

Expand Down Expand Up @@ -120,6 +123,14 @@ jobs:
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 != ''
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
cat version.json

- name: Build wheels
run: |
python3 -m build --wheel --outdir wheelhouse/ .
Expand Down Expand Up @@ -150,6 +161,14 @@ jobs:
path: dist/amalgam_lang-*.whl
if-no-files-found: error

workflow-summary:
needs: ["build"]
uses: "./.github/workflows/workflow-summary.yml"
secrets: inherit
with:
payload: "${{ inputs.payload }}"
build-type: "${{ inputs.build-type }}"

test-3-8:
needs: ["build"]
uses: "./.github/workflows/pytest.yml"
Expand Down Expand Up @@ -177,3 +196,49 @@ jobs:
secrets: inherit
with:
python-version: "3.11"

create-release:
if: inputs.build-type == 'release'
needs: ['build', 'test-3-8', 'test-3-9', 'test-3-10', 'test-3-11']
runs-on: ubuntu-latest
environment:
name: pypi
permissions:
contents: write
id-token: write

steps:

- uses: actions/checkout@v3

- name: Download Artifacts
uses: actions/download-artifact@v3
with:
path: ./tmp

- name: Clean up dir
run: |
mkdir -p dist
find ./tmp -type f -name '*.whl' -exec mv -t ./dist {} +
find ./tmp -type f -name '*.tar.gz' -exec mv -t ./dist {} +
ls ./dist

- name: Create Release
uses: ncipollo/release-action@v1
with:
tag: ${{ inputs.version }}
commit: ${{ github.sha }}
name: "amalgam-lang-py ${{ inputs.version }}"
artifactErrorsFailBuild: true
generateReleaseNotes: true
makeLatest: legacy
artifacts: "dist/*"
artifactContentType: application/gzip

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
9 changes: 5 additions & 4 deletions .github/workflows/create-branch-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,19 @@ jobs:
BRANCH_ITERATION=${{ github.run_attempt }}.${{ github.run_number }}
echo "version=$(echo ${{ steps.next-semvers.outputs.patch }}-alpha+BR.${{ github.ref_name }}.${BRANCH_ITERATION})" >> $GITHUB_OUTPUT

build-test-package:
build:
needs: ['set-branch-version']
uses: "./.github/workflows/build-test-package.yml"
uses: "./.github/workflows/build.yml"
secrets: inherit
with:
version: ${{ needs.set-branch-version.outputs.version }}
payload: ${{ inputs.payload }}
build-type: 'branch'

# This job is here to have only one final step to add for "Status Checks"
# in GitHub, instead of adding every leaf test from 'build-test-package'
# in GitHub, instead of adding every leaf test from 'build'
final-check:
needs: ['build-test-package']
needs: ['build']
if: always() && (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled'))
runs-on: ubuntu-latest
steps:
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/create-pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,18 @@ jobs:
PR_ITERATION=${{ github.run_attempt }}.${{ github.run_number }}
echo "version=$(echo ${{ steps.next-semvers.outputs.patch }}-alpha+PR.${PR_NUMBER}.${PR_ITERATION})" >> $GITHUB_OUTPUT

build-test-package:
build:
needs: ['set-pr-version']
uses: "./.github/workflows/build-test-package.yml"
uses: "./.github/workflows/build.yml"
secrets: inherit
with:
version: ${{ needs.set-pr-version.outputs.version }}
build-type: 'PR'

# This job is here to have only one final step to add for "Status Checks"
# in GitHub, instead of adding every leaf test from 'build-test-package'
# in GitHub, instead of adding every leaf test from 'build'
final-check:
needs: ['build-test-package']
needs: ['build']
if: always() && (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled'))
runs-on: ubuntu-latest
steps:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/create-release-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ jobs:

release:
needs: ['construct-release-tag']
uses: "./.github/workflows/release.yml"
uses: "./.github/workflows/build.yml"
secrets: inherit
with:
version: ${{ needs.construct-release-tag.outputs.release-tag }}
build-type: 'release'
17 changes: 15 additions & 2 deletions .github/workflows/get-dependency-details.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ on:
run-id:
description: "Run id to be used in GitHub CLI command for dependency query"
value: ${{ jobs.get-dependency-details.outputs.run-id }}
build-date:
description: "The datetime of the run (non-release)"
value: ${{ jobs.get-dependency-details.outputs.build-date }}
build-title:
description: "The display title of the run (non-release)"
value: ${{ jobs.get-dependency-details.outputs.build-title }}

defaults:
run:
Expand All @@ -36,6 +42,8 @@ jobs:
outputs:
run-type: ${{ steps.dependency.outputs.run-type }}
run-id: ${{ steps.dependency.outputs.run-id }}
build-date: ${{ steps.dependency.outputs.build-date }}
build-title: ${{ steps.dependency.outputs.build-title }}
steps:
- uses: actions/checkout@v3

Expand All @@ -48,10 +56,10 @@ jobs:
ID=""
if ! [[ -n "${{ inputs.payload }}" && $(echo '${{ inputs.payload }}' | jq 'has("${{ inputs.repo }}")') == true ]]; then
if [ "${{ inputs.skip-version-json-check }}" = true ]; then
echo "No JSON payload given, and skip-version-json-check flag is set. Exiting."
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, using version.json"
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'..."
Expand All @@ -76,6 +84,11 @@ jobs:
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
Expand Down
65 changes: 0 additions & 65 deletions .github/workflows/release.yml

This file was deleted.

67 changes: 67 additions & 0 deletions .github/workflows/workflow-summary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Reusable WF - Output Workflow Summary

on:
workflow_call:
inputs:
payload:
type: string
required: true
build-type:
type: string
required: true

defaults:
run:
shell: bash

jobs:

output-summary:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Download Artifacts
uses: actions/download-artifact@v3
with:
path: ./tmp

- name: Clean up dir
run: |
mkdir -p dist
mkdir -p amlg
find ./tmp -type f -name '*.whl' -exec mv -t ./amlg {} +

- name: Generate workflow summary
env:
GH_TOKEN: ${{ secrets.HOWSOAI_WORKFLOW_AUTOMATION_CLASSIC_TOKEN }}
run: |
pip install --user amlg/*-py3-none-any.whl

site_packages=$(python -m site --user-site)

if [[ $(cat $site_packages/amalgam/lib/version.json | jq '.version | has("amalgam_build_date")') == true ]]; then
# Get amalgam build title and date
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_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)
amlg_notes=$(echo "Release version specified in \`version.json\`")
fi
# amalgam notes
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
# Remove unecessary quotations from variable substitutions
sed -i "s|\"||g" ./.github/templates/version_summary.md
# Output filled template file to workflow summary
cat ./.github/templates/version_summary.md >> $GITHUB_STEP_SUMMARY
Loading