GitHub Packages, Releases, and Deployment
6 learning objectives Β· 11 key terms Β· 8 commands Β· 3 diagrams Β· 5 quiz questions
GitHub Packages, Releases, and Deployment
Automation & SecurityWhat you'll be able to do
- Create releases with version tags, notes and pre-release markers
- Publish packages to GitHub Packages from a workflow
- Build and push container images to GitHub Container Registry
- Deploy a static site with GitHub Pages
- Use environments, approvals and rollback strategy for deployments
- Automate the commit β build β test β package β deploy β monitor path
The idea, in plain language
A release is a tag plus communication. The tag keeps history honest β v2.5.0 points at exactly the commit that shipped β and the release page turns that tag into something a human can use: written notes, a compiled binary or archive, and a downloadable source snapshot. Pre-releases mark versions that are intentionally incomplete, and generated release notes assemble the list of merged pull requests for you, which is most of a changelog with none of the bookkeeping.
Packages are the distribution half: built artefacts that consumers install by name and version. GitHub Packages hosts npm, Maven, Gradle, NuGet, RubyGems, Docker and more under the same permissions model as your repository, which means your CI can publish with its built-in token rather than a separate service account. Container images go to Container Registry (ghcr.io), where the same workflow that ran your tests can build, tag and push an image, and where visibility follows the repository's.
Deployment is the last mile, and the safest version of it is boring. A static site can go straight to GitHub Pages on every push to main. A service should deploy through a pipeline that reuses the tested artefact rather than rebuilding, targets an environment whose secrets and approvals you have configured, and has a documented rollback β which for a versioned release is usually "deploy the previous tag". Monitoring closes the loop: a deployment that nobody measured is a guess, and the fastest rollback decision comes from a dashboard that was open before the deploy.
Key terms
- Tag
- A permanent name for a commit, used as the anchor for a release.
- Release
- A GitHub page attached to a tag, with notes and downloadable assets.
- Pre-release
- A release marked as not production-ready, such as v3.0.0-beta.1.
- Release notes
- The human-readable summary attached to a release; often generated from merged pull requests.
- GitHub Packages
- A package registry for npm, Maven, NuGet, RubyGems, containers and more.
- ghcr.io
- GitHub Container Registry, the Docker-compatible registry for container images.
- GitHub Pages
- Static hosting served from a repository branch or a workflow.
- Environment
- A named deployment target with its own secrets, protection rules and approvals.
- Deployment approval
- A required human sign-off before a job can deploy to an environment.
- Rollback
- Returning to a known-good version; usually re-deploying the previous tag.
- Immutable release
- A release whose assets and tag cannot be changed after publication.
How it works, step by step
- 1Tag the commit you are shipping
Use annotated tags for releases so the tag carries an author, date and message. Push it explicitly β tags are not sent by a normal push.
tagbashgit tag -a v2.5.0 -m "v2.5.0 β session handling improvements" git push origin v2.5.0
- 2Create the release
Attach notes and any built assets to the tag. Generated notes collect merged pull requests since the previous release, which is usually the changelog.
releasebashgh release create v2.5.0 --generate-notes dist/app.zip
- 3Mark betas as pre-releases
Pre-releases are excluded from "latest" and warn consumers they are testing something unfinished β the correct way to let users try a version without pretending it is stable.
pre-releasebashgh release create v3.0.0-beta.1 --prerelease --generate-notes
- 4Publish a package from CI
Authenticate with the built-in workflow token, set the registry in your package manager config, and publish as part of a release-triggered workflow so the package version always matches the tag.
publish to GitHub Packagesyamlpermissions: contents: read packages: write steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 20 registry-url: https://npm.pkg.github.com - run: npm ci && npm publish env: NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- 5Build and push a container image
Log in to ghcr.io with the workflow token, tag the image with the release version and commit SHA, and push. Consumers then pull a pinned version rather than an ambiguous latest.
container imageyaml- name: Log in to the registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push uses: docker/build-push-action@v6 with: push: true tags: ghcr.io/${{ github.repository }}:${{ github.ref_name }}
- 6Deploy a static site with Pages
For static sites, enable Pages with GitHub Actions as the source and upload the build output as a Pages artefact. Every push to main then publishes automatically.
GitHub Pagesyaml- uses: actions/configure-pages@v5 - uses: actions/upload-pages-artifact@v3 with: path: dist - uses: actions/deploy-pages@v4
- 7Gate deployment and plan the rollback
Attach production deploys to an environment with required reviewers, reuse the artefact that passed tests rather than rebuilding, and write down the rollback before you need it β usually "re-deploy tag v2.4.1".
environment with approvalyamljobs: deploy: runs-on: ubuntu-latest environment: name: production url: https://app.example.com steps: - run: ./deploy.sh v${{ github.ref_name }}
Commands worth memorising
Every block below is copy-ready β use the Copy button, then paste it into your terminal. Expected output is shown underneath so you know what βworkingβ looks like.
git tag -a v2.5.0 -m "v2.5.0 β session handling improvements" git push origin v2.5.0
* [new tag] v2.5.0 -> v2.5.0
Tags are not sent by a normal git push β they need their own push, and annotated tags carry the release message.
gh release create v2.5.0 --generate-notes dist/app.zip
https://github.com/ada/app/releases/tag/v2.5.0
--generate-notes lists the merged pull requests since the previous release; the trailing path attaches a downloadable asset.
gh release create v3.0.0-beta.1 --prerelease --generate-notes
The pre-release flag keeps it out of latest, so stable users are never offered it.
gh release view v2.5.0 --json tagName,isPrerelease,assets --jq .
{"assets":[],"isPrerelease":false,"tagName":"v2.5.0"}Confirms what actually shipped, which is the question every incident review starts with.
npm publish --registry=https://npm.pkg.github.com
In CI, authenticate with NODE_AUTH_TOKEN set to the built-in token and declare packages: write in the workflow permissions.
docker build -t ghcr.io/ada/app:2.5.0 . docker push ghcr.io/ada/app:2.5.0
Tag images with the release version as well as the commit SHA, so what is running is always identifiable.
gh release list --limit 5
v3.0.0-beta.1 Pre-release v3.0.0-beta.1 a day ago v2.5.0 Latest Session handling 3 days ago
The Latest and Pre-release markers tell you instantly which version users are being offered.
gh release view v2.4.1 --json tagName --jq .tagName
"v2.4.1"
The rollback command in practice: confirm the previous tag exists, then re-deploy that version.
Workflow diagrams
The artefact that reaches production is the artefact that passed tests β never a rebuild.
- A commit on main starts the pipeline.
- Build and test run on fresh runners; a red test stops everything downstream.
- The successful artefact is packaged and versioned, exactly once.
- Deployment targets an environment β with approval for production β and consumes the packaged artefact.
- Monitoring decides whether the release stands or the previous version goes back.
| Part | Purpose | Example |
|---|---|---|
| Annotated tag | Names the exact commit that shipped | v2.5.0 β 8c1d2ab |
| Release notes | Tells consumers what changed and whether to care | Generated from merged pull requests |
| Assets | Downloadable build output | app-2.5.0.zip, checksums.txt |
| Pre-release flag | Warns that the version is not production-ready | v3.0.0-beta.1 |
| Package version | What installers resolve by name | npm: my-lib@2.5.0 |
| Image tag | What orchestrators pull | ghcr.io/ada/app:2.5.0 |
A release is the tag plus everything a consumer needs to decide whether to use it.
- The tag is the identity: everything else points at it.
- Notes and assets are for humans; package and image tags are for machines.
- The pre-release flag prevents an unfinished version being treated as latest.
| Practice | Risk it removes |
|---|---|
| Deploy the tested artefact, not a rebuild | The tested code and the shipped code diverging |
| Environment-scoped secrets | Staging credentials working in production |
| Required reviewers on production | An unattended automated deploy going wrong |
| Versioned image tags, never just latest | Not knowing which code is running |
| Rollback documented as a tag | Improvised recovery under pressure |
| Smoke test after deploy | Discovering breakage from users |
Boring deploys are the goal: the excitement should be in the release notes, not the rollback.
- Reuse the artefact: build once, deploy the same bytes to every environment.
- Pin versions so "what is running" is answerable from the tag alone.
- Practise the rollback once, deliberately, so it is not new during an incident.
Worked example
A release-triggered workflow that publishes a package and creates the release, so version numbers cannot drift.
name: Release on: push: tags: ['v*'] permissions: contents: write packages: write pages: write id-token: write jobs: publish: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 20 registry-url: https://npm.pkg.github.com cache: npm - run: npm ci - run: npm test - run: npm publish env: NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Create release run: gh release create "${{ github.ref_name }}" --generate-notes env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Pushing a v* tag now tests, publishes the package at that exact version, and creates a release with generated notes. The version in the package and the tag can never disagree.
Where you'll use it
Common mistakes
- Building the artefact again in the deploy job instead of promoting the one that was tested.
- Publishing a package whose version does not match the git tag, so consumers and history disagree.
- Deploying only the latest image tag, which makes "what is running" unanswerable.
- Forgetting permissions: packages: write in the workflow and getting a confusing 403 from the registry.
- Letting production deploys run without an environment or approval, so a bad merge ships itself.
- Skipping the pre-release flag for a beta and having users treat it as stable.
- Having no rollback plan, then improvising one during an outage.
Best practices
- Tag with annotated tags, and generate release notes from merged pull requests.
- Trigger publish and deploy workflows from tags or from pushes to main, never from a laptop.
- Keep the package version, the image tag and the git tag identical.
- Deploy the artefact you tested, and pin versions rather than using latest.
- Scope production secrets to an environment with required reviewers.
- Write the rollback procedure, including the exact command, before you need it.
- Monitor after deploy, even if it is only a smoke test and an uptime check.
Hands-on exercise
Release a versioned artefact end to end
Tag, release, publish and deploy one project through a workflow.
- Add a release workflow triggered by tags matching v* with contents: write and packages: write permissions.
- Push an annotated tag v0.1.0 and confirm the workflow runs, tests pass and a release appears with generated notes.
- Add a step that publishes the project as a package (or uploads a built archive as a release asset) and check the package version matches the tag.
- Enable GitHub Pages for the repository using GitHub Actions as the source, and add a job that deploys a built static page.
- Create a production environment with yourself as a required reviewer, and point the deploy job at it β confirm the run waits for approval.
- Deliberately break a test, tag v0.1.1, and confirm no package and no release are published. Then fix it, tag v0.1.2, and write down the rollback command for v0.1.0.
π‘ Hint: If publishing is rejected with 403, the workflow is missing packages: write β the built-in token has no package permissions by default.
Done when: A tag creates a release with notes, the published artefact version matches the tag, Pages serves the site, and a broken test prevents publication entirely.
Checkpoint quiz
0 of 5 answered Β· 0 correct
- Multiple choiceQ1
Why trigger release workflows on tags rather than on every push to main?
- TroubleshootingQ2
Your publish step fails with 403 immediately after checkout and tests pass. What is the most likely cause?
- Multiple choiceQ3
What is the safest artefact to deploy to production?
- True or falseQ4
True or false: marking a release as a pre-release excludes it from being treated as the latest release.
- Multiple choiceQ5
What is the most useful thing to write down before deploying?
Module summary
- A release is an annotated tag plus notes, assets and an optional pre-release marker.
- Generate notes from merged pull requests and keep package, image and tag versions identical.
- GitHub Packages hosts npm, Maven, NuGet and more; containers go to ghcr.io; both use the repositoryβs permissions.
- Workflows need explicit permissions such as packages: write to publish.
- GitHub Pages can publish a static site directly from a workflow on every push to main.
- Deploy the artefact you tested, through an environment with approvals and environment-scoped secrets.
- Every deployment needs a written rollback before it needs one urgently.
Recommended resourcesAffiliate links Β· may earn us a commission
Recommended for learners
Practice what you learned
Put the GitHub course to work: open one of the company-wise repositories and follow the workflow you just learned, branch to release.