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 6, 2024
1 parent 2593199 commit 8f7b47d
Show file tree
Hide file tree
Showing 25 changed files with 887 additions and 722 deletions.
54 changes: 54 additions & 0 deletions .github/actions/audit-changelog/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: "Audit changelog"
description: "Get metadata about a changelog, including the expected file path, and if it exists"

inputs:
version:
description: "The version whose changelog is being audited"
required: true

outputs:
path:
description: "The expected file path to the change log, relative to the repo root"
value: ${{ steps.path.outputs.path }}
exists:
description: "Indicates if the changelog exists"
value: ${{ steps.exists.outputs.exists }}

runs:
using: composite
steps:
- name: "Parse version: `${{ inputs.version }}`"
id: semver
uses: dbt-labs/actions/[email protected]
with:
version: ${{ inputs.version }}

- name: "Set: path"
id: path
shell: bash
run: |
path=".changes/${{ steps.semver.outputs.base-version }}"
if [[ ${{ steps.semver.outputs.is-pre-release }} -eq 1 ]]
then
path+="-${{ steps.semver.outputs.pre-release }}"
fi
path+=".md"
echo "path=$path" >> $GITHUB_OUTPUT
- name: "Set: exists"
id: exists
shell: bash
run: |
exists=false
if test -f ${{ steps.path.outputs.path }}
then
exists=true
fi
echo "exists=exists">> $GITHUB_OUTPUT
- name: "[DEBUG] Changelog metadata"
shell: bash
run: |
echo version : ${{ inputs.version }}
echo path : ${{ steps.path.outputs.path }}
echo exists : ${{ steps.exists.outputs.exists }}
8 changes: 5 additions & 3 deletions .github/actions/audit-github-commit/action.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: "Audit GitHub commit"
description: "Get basic metadata associated with a commit"
description: "Get metadata about a commit"

inputs:
sha:
description: "The commit to audit"
required: true

outputs:
tag:
description: "The associated release tag, if the release exists"
Expand All @@ -22,7 +23,7 @@ outputs:
runs:
using: composite
steps:
- name: "Check if a release exists for this commit"
- name: "Check if a release exists for `${{ inputs.sha }}`"
id: commit
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -32,9 +33,10 @@ runs:
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"
- name: "[DEBUG] Commit metadata"
shell: bash
run: |
echo sha : ${{ inputs.sha }}
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 }}
Expand Down
25 changes: 10 additions & 15 deletions .github/actions/audit-github-tag/action.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
# 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"
description: "Get metadata about a release tag"

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

outputs:
exists:
description: "Does the tag exist?"
description: "Indicates if the tag exists"
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?"
description: "If the tag exists, indicates if it is a draft"
value: ${{ steps.draft.outputs.is-draft }}

runs:
using: composite
steps:
- name: "Check if tag exists"
- name: "Check if `${{ inputs.tag }}` exists in `${{ inputs.repo-url }}`"
id: tag
shell: bash
run: |
Expand All @@ -44,15 +38,15 @@ runs:
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: "Get commit associate with the tag"
- name: "Get the commit associated with `${{ inputs.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"
- name: "Check if `${{ inputs.tag }}` is a draft release"
id: draft
if: ${{ fromJSON(steps.tag.outputs.exists) == true }}
shell: bash
Expand All @@ -69,6 +63,7 @@ runs:
shell: bash
run: |
echo tag : ${{ inputs.tag }}
echo repo-url : ${{ inputs.repo-url }}
echo exists: : ${{ steps.release.outputs.exists }}
echo sha : ${{ steps.commit.outputs.sha }}
echo is-draft : ${{ steps.draft.outputs.is-draft }}
46 changes: 46 additions & 0 deletions .github/actions/audit-github-team/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: "Audit GitHub team"
description: "Get metadata about a GitHub team, such as a list of team members"

inputs:
organization:
description: "The GitHub organization that owns the team"
required: true
team:
description: "The name of the team"
required: true

outputs:
members:
description: "A space delimited list of team members"
value: ${{ steps.members.outputs.membership }}

runs:
using: composite
steps:
- name: "Set: output file name"
id: output-file
run: echo "name=output_$GITHUB_RUN_ID.json" >> $GITHUB_OUTPUT

- name: "Get team membership for `${{ inputs.organization }}/${{ inputs.team }}`"
run: |
url = orgs/${{ inputs.organization }}/teams/${{ inputs.team }}/members
header = Accept: application/vnd.github+json
gh api -H "$header" $url > ${{ steps.output-file.outputs.name }}
- name: "Parse team membership"
id: members
shell:
run: |
team_list=$(jq -r '.[].login' ${{ steps.output-file.outputs.name }})
team_list_single=$(echo $team_list | tr '\n' ' ')
echo "membership=$team_list_single" >> $GITHUB_OUTPUT
- name: "[DEBUG] Parse team membership"
shell: bash
run: |
echo organization : ${{ inputs.organization }}
echo team : ${{ inputs.team }}
echo members : ${{ steps.members.outputs.membership }}
- name: "Delete the output file"
run: rm ${{ steps.output-file.outputs.name }}
28 changes: 0 additions & 28 deletions .github/actions/build-archive-name/action.yml

This file was deleted.

34 changes: 34 additions & 0 deletions .github/actions/commit/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: "Commit changes"
description: "Commit changes and push back up to the remote"

inputs:
message:
description: "The commit message"
required: true
user:
description: "The user for the commit"
default: "Github Build Bot"
email:
description: "The email for the commit"
default: "[email protected]"

outputs:
path:
description: "The file path to the change log, relative to the repo root"
value: ${{ steps.path.outputs.path }}
exists:
description: "Does the changelog exist?"
value: ${{ steps.exists.outputs.exists }}

runs:
using: composite
steps:
- name: "Commit and push changes"
shell: bash
run: |
git config user.name "${{ inputs.user }}"
git config user.email "${{ inputs.email }}"
git pull
git add .
git commit -m "${{ inputs.message }}"
git push
35 changes: 35 additions & 0 deletions .github/actions/create-temp-branch/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: "Create temp branch"
description: "Create a unique temporary branch for running CI workflows, such as version bumps, changelog consolidation, etc."

inputs:
branch-stub:
description: "Stub to use for naming the branch (e.g. prep-release/, nightly-release/, etc.)"
default: "temp/"

outputs:
branch:
description: "Name of the newly created branch"
value: ${{ steps.branch.outputs.branch-name }}

runs:
using: composite
steps:
- name: "Create a unique branch name"
id: branch
run: |
name="${{ inputs.branch-stub }}"
name+="$(date +'%Y-%m-%d')/$GITHUB_RUN_ID"
echo "branch-name=$name" >> $GITHUB_OUTPUT
- name: "Create branch: `${{ steps.branch.outputs.branch-name }}`"
shell: bash
run: |
git checkout -b ${{ steps.branch.outputs.branch-name }}
git push -u origin ${{ steps.branch.outputs.branch-name }}
- name: "[INFO] Created branch"
shell: bash
run: |
title="Created branch"
message="${{ steps.branch.outputs.branch-name }}"
echo "::notice title=${{ env.NOTIFICATION_PREFIX }}: $title::$message"
3 changes: 1 addition & 2 deletions .github/actions/publish-github-draft/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ inputs:
runs:
using: composite
steps:

- name: "Download artifacts"
- name: "Download artifacts from `${{ inputs.archive-name }}`"
if: ${{ !(inputs.archive-name == "" }}
uses: actions/download-artifact@v4
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/actions/publish-github-full/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ inputs:
runs:
using: composite
steps:
- name: "Publish draft release"
- name: "Publish `${{ inputs.tag }}` as full 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"
- name: "[INFO] Published draft as full release"
shell: bash
run: |
title="Released draft as non-draft release on GitHub"
message="tag: ${{ inputs.tag }}"
message="tag: ${{ inputs.tag }} repo: ${{ inputs.repo-url }}"
echo "::notice title=${{ env.NOTIFICATION_PREFIX }}: $title::$message"
3 changes: 1 addition & 2 deletions .github/actions/publish-pypi/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ inputs:
runs:
using: composite
steps:

- name: "Download artifacts"
- name: "Download artifacts from `${{ inputs.archive-name }}`"
if: ${{ !(inputs.archive-name == "" }}
uses: actions/download-artifact@v4
with:
Expand Down
11 changes: 4 additions & 7 deletions .github/actions/publish-test-results/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ inputs:
source-file:
description: "File/directory to be uploaded"
required: true

outputs:
archive-name:
description: "Name of the archive containing the test artifacts"
Expand All @@ -22,16 +23,12 @@ outputs:
runs:
using: composite
steps:
- name: "Get timestamp for archive name"
id: timestamp
shell: bash
run: echo "ts=$(date +'%Y-%m-%dT%H-%M-%S')" >> $GITHUB_OUTPUT #no colons allowed for artifacts

- name: "Build archive name"
- name: "Create unique test archive name"
id: archive
shell: bash
run: |
archive_name = ${{ inputs.archive-type }}_python-${{ inputs.python-version }}_${{ inputs.os }}_${{ steps.timestamp.outputs.ts }}
timestamp=$(date +'%Y-%m-%dT%H-%M-%S') #no colons allowed for artifacts
archive_name = ${{ inputs.archive-type }}_python-${{ inputs.python-version }}_${{ inputs.os }}_$timestamp
echo "archive-name=archive_name" >> $GITHUB_OUTPUT
- name: "Upload test results"
Expand Down
16 changes: 16 additions & 0 deletions .github/actions/setup-changie/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Setup `changie`"
description: "Setup `changie` using `linuxbrew`"

runs:
using: composite
steps:
- name: "Add `linuxbrew` to PATH"
shell: bash
run: echo "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" >> $GITHUB_PATH

- name: "Install `linuxbrew` packages"
shell: bash
run: |
brew install pre-commit
brew tap miniscruff/changie https://github.com/miniscruff/changie
brew install changie
Loading

0 comments on commit 8f7b47d

Please sign in to comment.