Skip to content

Using GitHub CLI with GitHub Actions for Data Platform deployments

Reading Time: 4 minutes

In this post I want to share some advice about using GitHub CLI with GitHub Actions for Data Platform deployments. Because I showed that at SQLDay last week.

About GitHub CLI

For those who were not aware, there is a GitHub CLI you can use from the command line. You can download GitHub CLI from here.

Anyway, GitHub CLI was recently updated to support commands for GitHub Actions. GitHub Actions is the CI/CD mechanism that is now available in GitHub. Which I have covered in a few other posts, including the one you can find by clicking here.

Last week I did a GitHub CLI demo during our ‘GitHub DevOps Duet session’ whilst presenting at the online SQLDay conference.

With this in mind, I want to share some tips about using it for Data Platform deployments. In reality, most of these tips can also be used for other types of deployments as well. All the below command line screenshots were done using Windows Terminal.

GitHub CLI authentication

Depending on how you authenticate to GitHub your connection will automatically stay authenticated.

For example, authenticating using the below command will keep your laptop authenticated to your GitHub repository. Plus, the menu system it uses is helpful as well.

gh auth login

Data Platform repository location

Make sure you are in the location of your local clone of the repository in the command line before you start using GitHub CLI to view GitHub Action workflows.

GitHub CLI Hints

GitHub CLI gives you hints on the command you can run next as you dig deeper into workflows and jobs. For example, if I run ‘gh run list’ I get the below hint.

Using GitHub CLI with GitHub Actions for Data Platform deployments
gr run list results

If I run the hint to view a particular run, you will notice that a URL appears. When I hover over the URL it becomes underlined, and I get a tooltip appear telling me that I can open the link by pressing CTRL and clicking the mouse button. I think this is a very nice extra.

Using GitHub CLI with GitHub Actions for Data Platform deployments

If you do decide to follow these links though and you get to a stage where you can view the log of a job, make sure you add something at the end of the command to break down the log. Otherwise, you will get back a large amount of text.

For example, below I have used ‘| more’ to break up the results of the job log. However, others are available.

Using | more to break up results

Downloading Data Platform artifacts from GitHub

When I ran the ‘gh run view’ command for a specific run I get back a list of artifacts at the bottom as below.

gr run view with artifacts listed

One thing I can do from here is download one of these artifacts. For example, I can run the below command.

gh run download -n AzureSQLDB --dir c:\artifacts\AzureSQLDB

Once I have done this the contents of the artifact are downloaded into the specified folder as you can see below.

However, one thing to remember is that the folder should ideally be empty before you do this, otherwise you will get the below error:

error downloading AzureSQLDB: error extracting zip archive: error extracting "AzureSQLDB.dacpac": open c:\artifacts\AzureSQLDB.dacpac: The file exists.

Potential GitHub CLI rerun error

You can now use the rerun command in GitHub CLI to rerun a workflow. However, make sure you use this command when the workflow is not already running.

For example, I deployed the rerun command a few times for the below workflow. Based on the workflow in my post about how to deploy from one source to multiple SQL Server database types using GitHub Actions.

It deploys to three containers running SQL Server 2019, and Azure SQL Database and an Azure Synapse Analytics dedicated SQL Pool.

Using GitHub CLI with GitHub Actions for Data Platform deployments
GitHub Actions

In fact, it’s the same workflow we have been seeing from the GitHub CLI examples. To show this I have highlighted where the same artifacts can be shown.

Anyway, to demonstrate this I ran the ‘gh run rerun’ command three times.

As you can see below, it worked fine the first time. When I went to run it the second time straight afterwards, I got the highlighted error. Once the workflow had finished, I ran the command again just to show that it works.

So, the main point to take away from this is that the gh run rerun command does not queue up another run for you in GitHub Actions. You have to wait until the workflow has finished before you can try it again.

Final word about using GitHub CLI with GitHub Actions

I hope this advice about using GitHub CLI with GitHub Actions for Data Platform deployments has proven useful.

If you missed the demo at SQLDay I will show a version of it at SQL Saturday Los Angeles. Time permitting of course. You can find out more about that event here.

In the meantime, if you have any comments or queries feel free to reach out to me.

Published inAzure Synapse AnalyticsGitHubGitHub Actions

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *