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

automate internal release workflow. #1276

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft

Conversation

McKnight-42
Copy link
Contributor

https://github.com/dbt-labs/adapters-team-private/issues/168
docs dbt-labs/docs.getdbt.com/#

Problem

manually having to kick off the internal release workflow is a time eater, we can try to automate it as much as possible and just check it in the start of day.

Solution

add a cron job call for early mornings on a specified day a week (currently weds) and have the workflow first compare commit to last release if there is a new commit continue with release else don't.

Checklist

  • I have read the contributing guide and understand what's expected of me
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX

@McKnight-42 McKnight-42 self-assigned this Jul 10, 2024
@cla-bot cla-bot bot added the cla:yes label Jul 10, 2024
@McKnight-42 McKnight-42 added the Skip Changelog Skips GHA to check for changelog file label Jul 10, 2024
Copy link
Contributor

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the dbt-bigquery contributing guide.

Comment on lines 63 to 66
last_release_date=$(curl --silent "https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ needs.get-latest-release.outputs.latest_release }}" | jq -r .published_at)
new_commits=$(git rev-list --count --since="$last_release_date" ${{ inputs.ref }})
echo "::set-output name=new_commits::$new_commits"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to point somewhere else for this? won't internal releases be far ahead of the version releases? can we look at previous runs of this workflow and grab the commit from them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have updated workflow from this initial comment would love thoughts.

- name: Check for new commits since last release
id: check_new_commits
run: |
last_release_date=$(curl --silent "https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ needs.get-last-successful-run.outputs.commit_sha }}" | jq -r .published_at)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to retrieve commits not releases (i.e. we may not have a github release yet). Looks like this could work:
https://api.github.com/repos/dbt-labs/dbt-bigquery/commits/2c77893d0fb7b5d76ba85cc16712b9563a60329b

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updating this more this morning i'm starting to wonder if this should be its own action that triggers our current workflow to supply the fields we need that way. thoughts?

- name: Get last successful Release to Cloud run details
id: get_last_successful_release_run
run: |
last_run_url=$(curl --silent -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/actions/runs?event=workflow_dispatch&status=success&branch=${{ github.ref }}&workflow_file=release.internal.yml" | jq -r '.workflow_runs[0].url')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is pretty clever

@McKnight-42
Copy link
Contributor Author

question: should this be just releasing automatically off main or for every "supported" version

Copy link
Contributor

@mikealfare mikealfare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're mostly there, just a few nits and catches.

echo "Last run URL: $last_run_url"
commit_sha=$(curl --silent -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" $last_run_url | jq -r '.head_sha')
echo "Commit SHA: $commit_sha"
echo "::set-output name=commit_sha::$commit_sha"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be the new syntax that uses >> GITHUB_OUTPUT. I forget what it is off the top of my head, but it's something like echo "set commit_sha=$commit_sha" >> GITHUB_OUTPUT.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.github/workflows/release-internal.yml Outdated Show resolved Hide resolved
.github/workflows/release-internal.yml Show resolved Hide resolved
.github/workflows/release-internal.yml Outdated Show resolved Hide resolved
.github/workflows/release-internal.yml Outdated Show resolved Hide resolved
@mikealfare
Copy link
Contributor

question: should this be just releasing automatically off main or for every "supported" version

What do you mean by "supported" version? I think we're only ever releasing off main. And we do so as long as tests pass, which I guess means it's supported.

run: |
last_run_url=$(curl --silent -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/actions/runs?event=workflow_dispatch&status=success&branch=main&workflow_file=release-internal.yml" | jq -r '.workflow_runs[0].url')
echo "Last run URL: $last_run_url"
commit_sha=$(curl --silent -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" $last_run_url | jq -r '.head_sha')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way this can be None? Might be nice to validate and exit here if it's empty.

Comment on lines +67 to +68
# Get last successful Release to Cloud run details
last_run_url=$(curl --silent -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/actions/runs?event=workflow_dispatch&status=success&branch=main&workflow_file=release-internal.yml" | jq -r '.workflow_runs[0].url')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this appears to be operating unexpected, i'm targeting workflows based on the the specific file but the returned object from the dry_run was for an adapter integration test run

dry run
URL

@McKnight-42 McKnight-42 removed their assignment Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:yes Skip Changelog Skips GHA to check for changelog file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants