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

Add version bump and changelog #104

Merged
merged 38 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
3a6c1c7
use target_branch instead of just main
colin-rogers-dbt Feb 22, 2024
b3253ba
Bumping version to 0.1.0a7 and generate changelog
FishtownBuildBot Feb 22, 2024
c2ef847
[Automated] Merged prep-release/test/0.1.0a7_8012445474 into target b…
FishtownBuildBot Feb 22, 2024
168fb30
specify artifact_name
colin-rogers-dbt Feb 22, 2024
0819b2b
Merge remote-tracking branch 'fork/bumpVersion' into bumpVersion
colin-rogers-dbt Feb 22, 2024
1a728a9
specify artifact_name
colin-rogers-dbt Feb 22, 2024
d691e03
specify artifact_name
colin-rogers-dbt Feb 22, 2024
e151d83
add github-release.yml
colin-rogers-dbt Feb 22, 2024
84e45eb
remove unnecessary extra artifact build/upload
colin-rogers-dbt Feb 23, 2024
66cfcb4
remove unnecessary extra artifact build/upload
colin-rogers-dbt Feb 23, 2024
f5aa78f
remove duplicate build steps
colin-rogers-dbt Feb 23, 2024
3a65535
set download path in github-release.yml
colin-rogers-dbt Feb 23, 2024
7e79d38
add resolve_commit_sha
colin-rogers-dbt Feb 23, 2024
a099c5c
always resolve commit sha
colin-rogers-dbt Feb 23, 2024
e1c1c5d
always resolve commit sha
colin-rogers-dbt Feb 23, 2024
6ab541c
get sha and changelog path
colin-rogers-dbt Feb 23, 2024
d2965be
fix formatting
colin-rogers-dbt Feb 23, 2024
67fae59
fix formatting
colin-rogers-dbt Feb 23, 2024
4dee1a0
Revert "Bumping version to 0.1.0a7 and generate changelog"
colin-rogers-dbt Feb 23, 2024
7b8a93d
add changelog to archive
colin-rogers-dbt Feb 23, 2024
5d48702
add changelog to archive
colin-rogers-dbt Feb 23, 2024
030d679
specify action version
colin-rogers-dbt Feb 26, 2024
59520db
specify action version
colin-rogers-dbt Feb 26, 2024
29cf930
specify action version
colin-rogers-dbt Feb 26, 2024
04dde04
have gha release use sha
colin-rogers-dbt Feb 26, 2024
d1fd19d
log expected files in workflow
colin-rogers-dbt Feb 26, 2024
ebc693c
fix deploy_to logic
colin-rogers-dbt Feb 26, 2024
08e416f
add pypi checkout
colin-rogers-dbt Feb 26, 2024
9257252
fix pypi input name
colin-rogers-dbt Feb 27, 2024
6942e2d
add id-token permission
colin-rogers-dbt Feb 27, 2024
1eca8d9
Merge branch 'main' into bumpVersion
colin-rogers-dbt Feb 27, 2024
19c0088
standardize on artifacts-name
colin-rogers-dbt Feb 27, 2024
1653ee8
Merge remote-tracking branch 'fork/bumpVersion' into bumpVersion
colin-rogers-dbt Feb 27, 2024
edcdb2e
change to archive name
colin-rogers-dbt Feb 27, 2024
dfaf0ec
Merge branch 'main' into bumpVersion
colin-rogers-dbt Feb 27, 2024
3ca7622
update dev branch refs to main
colin-rogers-dbt Feb 27, 2024
ae5e143
Merge remote-tracking branch 'fork/bumpVersion' into bumpVersion
colin-rogers-dbt Feb 27, 2024
6adf31c
Update .github/workflows/github-release.yml
colin-rogers-dbt Feb 27, 2024
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
14 changes: 10 additions & 4 deletions .github/actions/build-hatch/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ inputs:
working-dir:
description: Where to run commands from, supports namespace packaging
default: "./"
artifacts-dir:
artifacts-name:
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
description: Where to upload the artifacts
default: "dist"
required: true
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
changelog-path:
description: Path to changelog file
required: true
mikealfare marked this conversation as resolved.
Show resolved Hide resolved

runs:
using: composite
Expand All @@ -32,5 +35,8 @@ runs:
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.artifacts-dir}}
path: ${{ inputs.working-dir }}dist/
name: ${{ inputs.artifacts-name}}
path: |
${{ inputs.changelog-path }}
${{ inputs.working-dir }}dist/
retention-days: 3
4 changes: 2 additions & 2 deletions .github/actions/publish-pypi/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish - PyPI
description: Publish artifacts saved during build step to PyPI

inputs:
artifacts-dir-name:
artifacts-name:
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
description: Where to download the artifacts from
required: true
repository-url:
Expand All @@ -16,7 +16,7 @@ runs:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: ${{ inputs.artifacts-dir }}
name: ${{ inputs.artifacts-name }}
path: .

- name: Publish artifacts to PyPI
Expand Down
259 changes: 259 additions & 0 deletions .github/workflows/github-release.yml
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
# **what?**
# Create a new release on GitHub and include any artifacts in the `/dist` directory of the GitHUb artifacts store.
colin-rogers-dbt marked this conversation as resolved.
Show resolved Hide resolved
#
# Inputs:
# sha: The commit to attach to this release
# version_number: The release version number (i.e. 1.0.0b1, 1.2.3rc2, 1.0.0)
# changelog_path: Path to the changelog file for release notes
# test_run: Test run (Publish release as draft)
#
# **why?**
# Reusable and consistent GitHub release process.
#
# **when?**
# Call after a successful build. Build artifacts should be ready to release and live in a dist/ directory.
#
# This workflow expects the artifacts to already be built and living in the artifact store of the workflow.
#
# Validation Checks
#
# 1. If no release already exists for this commit and version, create the tag and release it to GitHub.
# 2. If a release already exists for this commit, skip creating the release but finish with a success.
# 3. If a release exists for this commit under a different tag, fail.
# 4. If the commit is already associated with a different release, fail.

name: GitHub Release

on:
workflow_call:
inputs:
sha:
description: The commit to attach to this release
required: true
type: string
version_number:
description: The release version number (i.e. 1.0.0b1)
required: true
type: string
changelog_path:
description: Path to the changelog file for release notes
required: true
type: string
test_run:
description: Test run (Publish release as draft)
required: true
type: boolean
artifact_name:
description: artifact name to download
required: true
type: string
outputs:
tag:
description: The path to the changelog for this version
value: ${{ jobs.check-release-exists.outputs.tag }}

permissions:
contents: write

env:
REPO_LINK: ${{ github.server_url }}/${{ github.repository }}
NOTIFICATION_PREFIX: "[GitHub Release]"

jobs:
log-inputs:
runs-on: ubuntu-latest
steps:
- name: "[DEBUG] Print Variables"
run: |
echo The last commit sha in the release: ${{ inputs.sha }}
echo The release version number: ${{ inputs.version_number }}
echo Expected Changelog path: ${{ inputs.changelog_path }}
echo Test run: ${{ inputs.test_run }}
echo Repo link: ${{ env.REPO_LINK }}
echo Notification prefix: ${{ env.NOTIFICATION_PREFIX }}

check-release-exists:
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
outputs:
exists: ${{ steps.release_check.outputs.exists }}
draft_exists: ${{ steps.release_check.outputs.draft_exists }}
tag: ${{ steps.set_tag.outputs.tag }}

steps:
- name: "Generate Release Tag"
id: set_tag
run: echo "tag=v${{ inputs.version_number }}" >> $GITHUB_OUTPUT

# 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 exists so we can go ahead and 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 does, 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: "Check If Release Exists For Tag ${{ steps.set_tag.outputs.tag }}"
id: release_check
run: |
output=$((gh release view ${{ steps.set_tag.outputs.tag }} --json isDraft,targetCommitish --repo ${{ env.REPO_LINK }}) 2>&1) || true
if [[ "$output" == "release not found" ]]
then
title="Release for tag ${{ steps.set_tag.outputs.tag }} does not exist."
message="Check passed."
echo "exists=false" >> $GITHUB_OUTPUT
echo "draft_exists=false" >> $GITHUB_OUTPUT
echo "::notice title=${{ env.NOTIFICATION_PREFIX }}: $title::$message"
exit 0
fi
commit=$(jq -r '.targetCommitish' <<< "$output")
if [[ $commit != ${{ inputs.sha }} ]]
then
title="Release for tag ${{ steps.set_tag.outputs.tag }} already exists for commit $commit!"
message="Cannot create a new release for commit ${{ inputs.sha }}. Exiting."
echo "::error title=${{ env.NOTIFICATION_PREFIX }}: $title::$message"
exit 1
fi
isDraft=$(jq -r '.isDraft' <<< "$output")
if [[ $isDraft == true ]] && [[ ${{ inputs.test_run }} == false ]]
then
title="Release tag ${{ steps.set_tag.outputs.tag }} already associated with the draft release."
message="Release workflow will publish the associated release."
echo "exists=false" >> $GITHUB_OUTPUT
echo "draft_exists=true" >> $GITHUB_OUTPUT
echo "::notice title=${{ env.NOTIFICATION_PREFIX }}: $title::$message"
exit 0
fi
title="Release for tag ${{ steps.set_tag.outputs.tag }} already exists."
message="Skip GitHub Release Publishing."
echo "exists=true" >> $GITHUB_OUTPUT
echo "draft_exists=false" >> $GITHUB_OUTPUT
echo "::notice title=${{ env.NOTIFICATION_PREFIX }}: $title::$message"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ env.REPO_LINK }}

- name: "[DEBUG] Log Job Outputs"
run: |
echo exists: ${{ steps.release_check.outputs.exists }}
echo draft_exists: ${{ steps.release_check.outputs.draft_exists }}
echo tag: ${{ steps.set_tag.outputs.tag }}

skip-github-release:
runs-on: ubuntu-latest
needs: [check-release-exists]
if: needs.check-release-exists.outputs.exists == 'true'

steps:
- name: "Tag Exists, Skip GitHub Release Job"
run: |
echo title="A tag already exists for ${{ needs.check-release-exists.outputs.tag }} and commit."
echo message="Skipping GitHub release."
echo "::notice title=${{ env.NOTIFICATION_PREFIX }}: $title::$message"

audit-release-different-commit:
runs-on: ubuntu-latest
needs: [check-release-exists]
if: needs.check-release-exists.outputs.exists == 'false'

steps:
- name: "Check If Release Already Exists For Commit"
uses: cardinalby/[email protected]
id: check_release_commit
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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"
run: |
echo steps.check_release_commit.outputs.id: ${{ steps.check_release_commit.outputs.id }}
echo steps.check_release_commit.outputs.tag_name: ${{ steps.check_release_commit.outputs.tag_name }}
echo steps.check_release_commit.outputs.target_commitish: ${{ steps.check_release_commit.outputs.target_commitish }}
echo steps.check_release_commit.outputs.prerelease: ${{ steps.check_release_commit.outputs.prerelease }}

# Since we already know a release for this tag does not exist, if we find anything it's for the wrong tag, exit
- name: "Check If The Tag Matches The Version Number"
if: steps.check_release_commit.outputs.id != ''
run: |
title="Tag ${{ steps.check_release_commit.outputs.tag_name }} already exists for this commit!"
message="Cannot create a new tag for ${{ needs.check-release-exists.outputs.tag }} for the same commit"
echo "::error title=${{ env.NOTIFICATION_PREFIX }}: $title::$message"
exit 1

publish-draft-release:
runs-on: ubuntu-latest
needs: [check-release-exists, audit-release-different-commit]
if: >-
needs.check-release-exists.outputs.draft_exists == 'true' &&
inputs.test_run == false

steps:
- name: "Publish Draft Release - ${{ needs.check-release-exists.outputs.tag }}"
run: |
gh release edit $TAG --draft=false --repo ${{ env.REPO_LINK }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ needs.check-release-exists.outputs.tag }}

create-github-release:
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
needs: [check-release-exists, audit-release-different-commit]
if: needs.check-release-exists.outputs.draft_exists == 'false'

steps:
- name: "Check out repository"
uses: actions/checkout@v4
with:
ref: ${{ inputs.sha }}

- name: "Download Artifact ${{ inputs.artifact_name }}"
uses: actions/download-artifact@v3
with:
name: ${{ inputs.artifact_name }}
path: .

- name: "[DEBUG] Display Structure Of Expected Files"
run: |
ls -R .changes
ls -l dist

- name: "Set Release Type"
id: release_type
run: |
if ${{ contains(inputs.version_number, 'rc') || contains(inputs.version_number, 'b') }}
then
echo Release will be set as pre-release
echo "prerelease=--prerelease" >> $GITHUB_OUTPUT
else
echo This is not a prerelease
fi

- name: "Set As Draft Release"
id: draft
run: |
if [[ ${{ inputs.test_run }} == true ]]
then
echo Release will be published as draft
echo "draft=--draft" >> $GITHUB_OUTPUT
else
echo This is not a draft release
fi

- name: "GitHub Release Workflow Annotation"
run: |
title="Release ${{ needs.check-release-exists.outputs.tag }}"
message="Configuration: ${{ steps.release_type.outputs.prerelease }} ${{ steps.draft.outputs.draft }}"
echo "::notice title=${{ env.NOTIFICATION_PREFIX }}: $title::$message"

- name: "Create New GitHub Release - ${{ needs.check-release-exists.outputs.tag }}"
run: |
gh release create $TAG ./dist/* --title "$TITLE" --notes-file $RELEASE_NOTES --target $COMMIT $PRERELEASE $DRAFT --repo ${{ env.REPO_LINK }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ needs.check-release-exists.outputs.tag }}
TITLE: ${{ github.event.repository.name }} ${{ needs.check-release-exists.outputs.tag }}
RELEASE_NOTES: ${{ inputs.changelog_path }}
COMMIT: ${{ inputs.sha }}
PRERELEASE: ${{ steps.release_type.outputs.prerelease }}
DRAFT: ${{ steps.draft.outputs.draft }}
Loading
Loading