Skip to content

Commit

Permalink
break workflows into actions and smaller workflows, reuse workflows i…
Browse files Browse the repository at this point in the history
…n larger workflows
  • Loading branch information
mikealfare committed Mar 3, 2024
1 parent 2a99e36 commit 2593199
Show file tree
Hide file tree
Showing 19 changed files with 686 additions and 485 deletions.
41 changes: 41 additions & 0 deletions .github/actions/audit-github-commit/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: "Audit GitHub commit"
description: "Get basic metadata associated with a commit"

inputs:
sha:
description: "The commit to audit"
required: true
outputs:
tag:
description: "The associated release tag, if the release exists"
value: ${{ steps.commit.outputs.tag_name }}
release-id:
description: "The associated release id, if the release exists"
value: ${{ steps.commit.outputs.id }}
pre-release:
description: "If the associated release exists, is it a pre-release?"
value: ${{ steps.commit.outputs.prerelease }}
commitish:
description: "The associated commitish, if the release exists"
value: ${{ steps.commit.outputs.target_commitish }}

runs:
using: composite
steps:
- name: "Check if a release exists for this commit"
id: commit
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: cardinalby/[email protected]
with:
commitSha: ${{ inputs.sha }}
doNotFailIfNotFound: true # returns blank outputs when not found instead of error
searchLimit: 15 # Since we only care about recent releases, speed up the process

- name: "[DEBUG] Print Release Details"
shell: bash
run: |
echo tag : ${{ steps.check_release_commit.outputs.tag_name }}
echo release-id : ${{ steps.check_release_commit.outputs.id }}
echo pre-release : ${{ steps.check_release_commit.outputs.prerelease }}
echo commitish : ${{ steps.check_release_commit.outputs.target_commitish }}
74 changes: 74 additions & 0 deletions .github/actions/audit-github-tag/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# When the GitHub CLI doesn't find a release for the given tag, it will exit 1 with a
# message of "release not found". In our case, it's not an actual error, just a
# confirmation that the release does not already exist, so we can create it.
# The `|| true` makes it so the step does not exit with a non-zero exit code.
# Also check if the release already exists is draft state. If it's a draft,
# and we are not testing, then we can publish that draft as-is. If it's in draft,
# and we are testing, skip the release.
name: "Audit GitHub tag"
description: "Get basic metadata associated with a release tag"

inputs:
tag:
description: "The tag to audit (i.e. v1.0.0b1)"
required: true
repo-url:
description: "The URL to the repo (https://github.com/dbt-labs/dbt-adapters"
required: true
outputs:
exists:
description: "Does the tag exist?"
value: ${{ steps.tag.outputs.exists }}
sha:
description: "The commit associated with the tag if the tag exists"
value: ${{ steps.commit.outputs.sha }}
is-draft:
description: "If the tag exists, is it a draft?"
value: ${{ steps.draft.outputs.is-draft }}

runs:
using: composite
steps:
- name: "Check if tag exists"
id: tag
shell: bash
run: |
output=$((gh release view ${{ inputs.tag }} --json isDraft,targetCommitish --repo ${{ inputs.repo-url }}) 2>&1) || true
echo "results=$output" >> $GITHUB_OUTPUT
if [[ "$output" == "release not found" ]]
then
echo "exists=false" >> $GITHUB_OUTPUT
else
echo "exists=true" >> $GITHUB_OUTPUT
fi
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: "Get commit associate with the tag"
id: commit
if: ${{ fromJSON(steps.tag.outputs.exists) == true }}
shell: bash
run: |
sha=$(jq -r '.targetCommitish' <<< "$output")
echo "sha=$sha" >> $GITHUB_OUTPUT
- name: "Check if tag is a draft release"
id: draft
if: ${{ fromJSON(steps.tag.outputs.exists) == true }}
shell: bash
run: |
is-draft=$(jq -r '.isDraft' <<< "${{ steps.tag.outputs.results }}")
if [[ $is-draft == true ]]
then
echo "is-draft=true" >> $GITHUB_OUTPUT
else
echo "is-draft=false" >> $GITHUB_OUTPUT
fi
- name: "[DEBUG] Tag metadata"
shell: bash
run: |
echo tag : ${{ inputs.tag }}
echo exists: : ${{ steps.release.outputs.exists }}
echo sha : ${{ steps.commit.outputs.sha }}
echo is-draft : ${{ steps.draft.outputs.is-draft }}
28 changes: 28 additions & 0 deletions .github/actions/build-archive-name/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Build"
description: "Provide a standard archive name for build artifacts"

inputs:
package:
description: "Choose what to publish"
required: true
version:
description: "The release version number (i.e. 1.0.0b1)"
required: true
deploy-to:
description: "Choose where to publish"
default: prod
outputs:
archive-name:
description: "A unique archive name"
value: ${{ steps.archive.outputs.archive-name }}

runs:
using: composite

steps:
- name: "Archive name"
id: archive
shell: bash
run: |
archive_name=${{ inputs.package }}-${{ inputs.version }}-${{ inputs.deploy-to }}
echo "archive-name=$archive_name" >> $GITHUB_OUTPUT
37 changes: 0 additions & 37 deletions .github/actions/build-hatch/action.yml

This file was deleted.

72 changes: 72 additions & 0 deletions .github/actions/publish-github-draft/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: "Publish to GitHub as draft release"
description: "Publish artifacts from an archive to GitHub as a draft release"

inputs:
archive-name:
description: "Name of the archive containing the artifacts, leave blank if local"
default: ""
tag:
description: "The release tag to publish under"
required: true
repo-url:
description: "The URL to the repo (https://github.com/dbt-labs/dbt-adapters"
required: true
sha:
description: "Commit SHA being released"
required: true
changelog-path:
description: "Path to the release notes"
required: true

runs:
using: composite
steps:

- name: "Download artifacts"
if: ${{ !(inputs.archive-name == "" }}
uses: actions/download-artifact@v4
with:
name: ${{ inputs.archive-name }}
path: dist/

- name: "[INFO] Downloaded artifacts"
if: ${{ !(inputs.archive-name == "" }}
shell: bash
run: |
title="Downloaded artifacts"
message="Downloaded artifacts from ${{ inputs.archive-name }}"
echo "::notice title=${{ env.NOTIFICATION_PREFIX }}: $title::$message"
- name: "[DEBUG] Found artifacts"
shell: bash
working-directory: ${{ inputs.working-dir }}
run: echo $(ls ./dist)

- name: "Set: pre-release"
id: pre-release
shell: bash
run: |
if ${{ contains(inputs.tag, 'rc') || contains(inputs.tag, 'b') || contains(inputs.tag, 'a') }}
then
echo "pre-release=--prerelease" >> $GITHUB_OUTPUT
fi
- name: "Publish artifacts to GitHub as draft release"
shell: bash
run: |
gh release create $TAG ./dist/* --title "$TITLE" --notes-file $RELEASE_NOTES --target $COMMIT $PRERELEASE --draft --repo ${{ inputs.repo-url }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ inputs.tag }}
TITLE: ${{ github.event.repository.name }} ${{ inputs.tag }}
RELEASE_NOTES: ${{ inputs.changelog-path }}
COMMIT: ${{ inputs.sha }}
PRERELEASE: ${{ steps.pre-release.outputs.pre-release }}
DRAFT: ${{ inputs.draft-flag }}

- name: "[INFO] Published artifacts to GitHub as draft release"
shell: bash
run: |
title="Published artifacts to GitHub as draft release"
message="artifacts: $(ls ./dist) tag: ${{ inputs.tag }} pre-release: ${{ steps.prerelease.outputs.prerelease }}"
echo "::notice title=${{ env.NOTIFICATION_PREFIX }}: $title::$message"
26 changes: 26 additions & 0 deletions .github/actions/publish-github-full/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "Publish GitHub draft release as full release"
description: "Publish an existing draft release as a non-draft release"

inputs:
tag:
description: "The tag to publish (i.e. v1.0.0b1)"
required: true
repo-url:
description: "The URL to the repo (https://github.com/dbt-labs/dbt-adapters"
required: true

runs:
using: composite
steps:
- name: "Publish draft release"
shell: bash
run: gh release edit ${{ inputs.tag }} --draft=false --repo ${{ inputs.repo-url }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: "[INFO] Released draft as non-draft release on GitHub"
shell: bash
run: |
title="Released draft as non-draft release on GitHub"
message="tag: ${{ inputs.tag }}"
echo "::notice title=${{ env.NOTIFICATION_PREFIX }}: $title::$message"
42 changes: 32 additions & 10 deletions .github/actions/publish-pypi/action.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,51 @@
name: Publish - PyPI
description: Publish artifacts saved during build step to PyPI
name: "Publish to PyPI"
description: "Publish artifacts from an archive to PyPI"

inputs:
archive-name:
description: Where to download the artifacts from
required: true
description: "Name of the archive containing the artifacts, leave blank if local"
default: ""
repository-url:
description: The PyPI index to publish to, test or prod
description: "The url for the PyPI index"
required: true
working-dir:
description: "Where to run commands from, primarily supports namespace packaging"
default: "./"

runs:
using: composite
steps:

- name: Download artifacts
uses: actions/download-artifact@v3
- name: "Download artifacts"
if: ${{ !(inputs.archive-name == "" }}
uses: actions/download-artifact@v4
with:
name: ${{ inputs.archive-name }}
path: dist/

- name: "[DEBUG]"
run : ls -R
- name: "[INFO] Downloaded artifacts"
if: ${{ !(inputs.archive-name == "" }}
shell: bash
run: |
title="Downloaded artifacts"
message="Downloaded artifacts from ${{ inputs.archive-name }}"
echo "::notice title=${{ env.NOTIFICATION_PREFIX }}: $title::$message"
- name: "[DEBUG] Found artifacts"
shell: bash
working-directory: ${{ inputs.working-dir }}
run: echo $(ls ./dist)

- name: Publish artifacts to PyPI
- name: "Publish artifacts to PyPI"
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: ${{ inputs.repository-url }}
packages-dir: ${{ inputs.working-dir }}dist/

- name: "[INFO] Published artifacts to PyPI"
shell: bash
working-directory: ${{ inputs.working-dir }}
run: |
title="Published artifacts to PyPI"
message=$(ls ./dist)
echo "::notice title=${{ env.NOTIFICATION_PREFIX }}: $title::$message"
25 changes: 0 additions & 25 deletions .github/actions/publish-results/action.yml

This file was deleted.

Loading

0 comments on commit 2593199

Please sign in to comment.