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

Closed
wants to merge 11 commits into from
46 changes: 41 additions & 5 deletions .github/workflows/release-internal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#
# When?
#
# Manual trigger.
# Manual trigger or cron job every wednesday morning.
McKnight-42 marked this conversation as resolved.
Show resolved Hide resolved

name: "Release to Cloud"
run-name: "Release to Cloud off of ${{ inputs.ref }}"
Expand All @@ -32,20 +32,56 @@ on:
required: true
default: false

schedule:
- cron: '0 13 * * 3' # Every Wednesday at 8:00 AM central time

defaults:
run:
shell: bash

jobs:
get-last-successful-release-run:
runs-on: ubuntu-latest
outputs:
commit_sha: ${{ steps.get_last_successful_release_run.outputs.commit_sha }}
steps:
- 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

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.

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.


check-for-new-commits:
runs-on: ubuntu-latest
needs: get-last-successful-release-run
outputs:
latest_commit_sha: ${{ steps.check_new_commits.outputs.latest_commit_sha }}
has_new_commits: ${{ steps.check_new_commits.outputs.has_new_commits }}
steps:
- name: Check for new commits since last Release to Cloud run
id: check_new_commits
run: |
last_commit_sha=${{ needs.get-last-successful-release-run.outputs.commit_sha }}
echo "Last successful commit SHA: $last_commit_sha"
latest_commit_sha=$(git rev-parse ${{ inputs.ref }})
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
echo "Latest commit SHA: $latest_commit_sha"
if [ "$last_commit_sha" != "$latest_commit_sha" ]; then
McKnight-42 marked this conversation as resolved.
Show resolved Hide resolved
echo "::set-output name=has_new_commits::true"
McKnight-42 marked this conversation as resolved.
Show resolved Hide resolved
else
echo "::set-output name=has_new_commits::false"
fi
echo "::set-output name=latest_commit_sha::$latest_commit_sha"

invoke-reusable-workflow:
if: needs.check-for-new-commits.outputs.has_new_commits == 'true'
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
name: "Build and Release Internally"

uses: "dbt-labs/dbt-release/.github/workflows/internal-archive-release.yml@main"

with:
package_test_command: "${{ inputs.package_test_command }}"
dbms_name: "bigquery"
ref: "${{ inputs.ref }}"
skip_tests: "${{ inputs.skip_tests }}"

secrets: "inherit"
McKnight-42 marked this conversation as resolved.
Show resolved Hide resolved
secrets: inherit
Loading