Skip to main content
Build artifacts and approving a deployment
This course material was developed as part of UNIVERSE-HPC, which was funded through the SPF ExCALIBUR programme under grant number EP/W035731/1

This course material was developed as part of UNIVERSE-HPC, which was funded through the SPF ExCALIBUR programme under grant number EP/W035731/1

Creative Commons License

Build artifacts and approving a deployment

Everything a run makes is thrown away

When a job finishes, its runner is destroyed, and everything on it goes too.
That has been fine so far, because every workflow you have written answers a yes or no question. Did the linter pass? Did the tests pass? You only needed the answer, not anything the machine produced along the way.
There are two things that might change that.
The first is review. Your documentation workflow builds HTML and publishes it when a change reaches main. A reviewer looking at a pull request has no way to see what that HTML will look like until after they have approved it. A green build says the documentation compiled, which is not the same as saying it reads well, the links go anywhere, or the new section appears at all.
The second is deployment. Once you want a person to approve something before it goes live, the thing they approve has to still exist afterwards.
Both need the same mechanism.

Artifacts

An artifact is a set of files saved out of a workflow run.
It belongs to the run rather than to the repository, so it is not committed and does not appear in your git history. You will find it listed at the bottom of that run's own page in the Actions tab. It stays there after the runner is gone, so you can download it later, but not forever: artifacts are deleted after a retention period, which is 90 days by default and can be set for each upload.

Previewing the documentation from a pull request

Build a documentation preview

Write a workflow, docs_preview.yml, that runs on pull requests, builds the Sphinx HTML, and uploads it as an artifact.
Use actions/upload-artifact, and give the artifact a name you will recognise.
This workflow does not publish anything, so it only needs read access to the repository.

Review a change before merging it

Make a change you can see: edit the text of a docstring on one of the public functions, or add a paragraph to the quickstart page.
Open a pull request. When the workflow finishes, scroll to the bottom of the run's summary page, download documentation-preview, unzip it, and open index.html in a browser.
Check that your change appears, reads correctly, and has not broken the formatting around it.
Artifacts are useful for failures too. Sometimes a test produces a file that would help you understand why it failed: a log, a generated report, or an image that was supposed to match a reference. Uploading that file from the workflow is often much quicker than trying to reproduce the whole failure on your own machine.

Deploying what you reviewed

Now look again at the documentation workflow you wrote in the documentation section.
It has one job, and that job checks out the code, builds the HTML, and publishes it. Three problems follow from that.
It does not run the tests, so documentation can be published from a commit that is broken.
It builds and publishes in the same job, so the thing that goes live was never a separate, inspectable object.
And, finally, nobody is asked for their approval. A push to main goes to real users, immediately.

Jobs that depend on other jobs

A workflow can have several jobs, and needs: makes one wait for another:
jobs: tests: runs-on: ubuntu-latest steps: ... build-docs: needs: tests runs-on: ubuntu-latest steps: ... deploy: needs: build-docs runs-on: ubuntu-latest steps: ...
Jobs without needs run in parallel, which is why your matrix jobs all start at once. A job with needs waits, and is skipped entirely if what it depends on failed.
That is the gate: deploy cannot run unless build-docs succeeded, which cannot run unless tests succeeded.
Each job gets a fresh runner, so a later job does not inherit the files an earlier one made. That is exactly what artifacts are for, and the Pages actions use them: upload-pages-artifact in one job, deploy-pages in another.

Split the deployment into three jobs

Rewrite pages.yml so that it has a tests job, a build-docs job and a deploy job, connected with needs:.
The documentation must be built exactly once. The deploy job should not check out the code or build anything.
Narrow the permissions too. At the moment the whole workflow can write to Pages; only the deployment needs to.

Asking a person

The workflow now refuses to deploy broken code. It still does not ask anyone.
environment: github-pages in that last job is doing more than labelling it. An environment is a named thing in your repository settings that can carry rules, and the most useful rule is that a human has to approve before any job using it will start.

Require an approval

In Settings, then Environments, open github-pages and add yourself as a required reviewer.
Make a documentation change and merge it, then watch what the workflow does.

Delivery, or deployment

You have now built both halves of a distinction the lecture made at the start.
Before you added the reviewer, a change that passed its checks went live on its own. That is Continuous Deployment.
After you added the reviewer, every change that passes is built, tested, packaged up and left ready to go, and a person decides when it goes. That is Continuous Delivery.
The pipeline is identical until the final step. The whole difference is whether a human has to say yes.
Neither one is the right answer in general. Deploying documentation automatically is sensible: the cost of a bad page is low, and fixing it just means pushing another commit. Deploying a service that people depend on, or anything that is awkward to undo, usually deserves the approval step, and in some regulated settings you will not have a choice about it.
The important thing is to make the decision on purpose. It is quite easy to end up deploying automatically simply because nobody ever stopped to think about whether you should!

Next steps

  1. [optional] read about storing workflow data as artifacts.
  2. [optional] read about deployment environments and the other protection rules they can carry, such as wait timers and branch restrictions.