Learn GitHub
$ gh ghautomation.ghpackages

GitHub Packages, Releases, and Deployment

6 learning objectives Β· 11 key terms Β· 8 commands Β· 3 diagrams Β· 5 quiz questions

$objectives

GitHub Packages, Releases, and Deployment

Automation & Security

Module 4 of 5 Β· lesson 15 in this module

What 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
$concept

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

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.
$steps

How it works, step by step

  1. 1
    Tag 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.

    tagbash
    git tag -a v2.5.0 -m "v2.5.0 β€” session handling improvements"
    git push origin v2.5.0
  2. 2
    Create 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.

    releasebash
    gh release create v2.5.0 --generate-notes dist/app.zip
  3. 3
    Mark 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-releasebash
    gh release create v3.0.0-beta.1 --prerelease --generate-notes
  4. 4
    Publish 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 Packagesyaml
    permissions:
      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 }}
  5. 5
    Build 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 }}
  6. 6
    Deploy 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
  7. 7
    Gate 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 approvalyaml
    jobs:
      deploy:
        runs-on: ubuntu-latest
        environment:
          name: production
          url: https://app.example.com
        steps:
          - run: ./deploy.sh v${{ github.ref_name }}
$commands

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.

tag the releasebash
git tag -a v2.5.0 -m "v2.5.0 β€” session handling improvements"
git push origin v2.5.0
Output
 * [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.

create the releasebash
gh release create v2.5.0 --generate-notes dist/app.zip
Output
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.

publish a betabash
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.

read a release backbash
gh release view v2.5.0 --json tagName,isPrerelease,assets --jq .
Output
{"assets":[],"isPrerelease":false,"tagName":"v2.5.0"}

Confirms what actually shipped, which is the question every incident review starts with.

publish a package to GitHub Packagesbash
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.

build and push a container imagebash
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.

list releasesbash
gh release list --limit 5
Output
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.

roll backbash
gh release view v2.4.1 --json tagName --jq .tagName
Output
"v2.4.1"

The rollback command in practice: confirm the previous tag exists, then re-deploy that version.

$diagrams

Workflow diagrams

Diagram 1From commit to production, with a way back

The artefact that reaches production is the artefact that passed tests β€” never a rebuild.

Reading the diagram
  1. A commit on main starts the pipeline.
  2. Build and test run on fresh runners; a red test stops everything downstream.
  3. The successful artefact is packaged and versioned, exactly once.
  4. Deployment targets an environment β€” with approval for production β€” and consumes the packaged artefact.
  5. Monitoring decides whether the release stands or the previous version goes back.
Diagram 2What a release contains

A release is the tag plus everything a consumer needs to decide whether to use it.

Reading the diagram
  1. The tag is the identity: everything else points at it.
  2. Notes and assets are for humans; package and image tags are for machines.
  3. The pre-release flag prevents an unfinished version being treated as latest.
Diagram 3Deployment safety checklist

Boring deploys are the goal: the excitement should be in the release notes, not the rollback.

Reading the diagram
  1. Reuse the artefact: build once, deploy the same bytes to every environment.
  2. Pin versions so "what is running" is answerable from the tag alone.
  3. Practise the rollback once, deliberately, so it is not new during an incident.
$example

Worked example

A release-triggered workflow that publishes a package and creates the release, so version numbers cannot drift.

.github/workflows/release.ymlyaml
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 }}
Output
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.
1on: push with tags: ['v*'] makes tagging the only way to trigger a release β€” no accidental publications from ordinary commits.
2The permissions block is least privilege in practice: reading contents, writing packages and releases, and nothing else. Without packages: write, npm publish is rejected.
3actions/setup-node with registry-url points npm at GitHub Packages instead of the public registry, and cache: npm keeps the install fast.
4Tests run before publishing. A failing test means no package and no release, which is exactly the ordering you want.
5npm publish uses the built-in GITHUB_TOKEN as NODE_AUTH_TOKEN, so no long-lived credential exists anywhere.
6The release is created from the same tag, with notes generated from merged pull requests. Tag, package version and release notes all describe the same commit.
$use cases

Where you'll use it

β–ΈShipping a library where consumers need tags, notes and a registry version that agree.
β–ΈDistributing a compiled CLI as a downloadable release asset.
β–ΈPublishing a container image that a Kubernetes cluster pulls by tag.
β–ΈHosting project documentation on GitHub Pages with every push to main.
β–ΈLetting users opt into a beta with a pre-release while stable users are unaffected.
β–ΈReleasing a hotfix as a new patch version with a documented rollback to the previous tag.
$mistakes

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

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.
$exercise

Hands-on exercise

Release a versioned artefact end to end

Tag, release, publish and deploy one project through a workflow.

  1. Add a release workflow triggered by tags matching v* with contents: write and packages: write permissions.
  2. Push an annotated tag v0.1.0 and confirm the workflow runs, tests pass and a release appears with generated notes.
  3. 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.
  4. Enable GitHub Pages for the repository using GitHub Actions as the source, and add a job that deploys a built static page.
  5. Create a production environment with yourself as a required reviewer, and point the deploy job at it β€” confirm the run waits for approval.
  6. 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.

$quiz

Checkpoint quiz

0 of 5 answered Β· 0 correct

  1. Multiple choiceQ1

    Why trigger release workflows on tags rather than on every push to main?

  2. TroubleshootingQ2

    Your publish step fails with 403 immediately after checkout and tests pass. What is the most likely cause?

  3. Multiple choiceQ3

    What is the safest artefact to deploy to production?

  4. True or falseQ4

    True or false: marking a release as a pre-release excludes it from being treated as the latest release.

  5. Multiple choiceQ5

    What is the most useful thing to write down before deploying?

$summary

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.

Next up: All of that automation is easier from the terminal. Module 13 covers the GitHub CLI, which turns issues, pull requests, runs and releases into single commands.

Recommended resourcesAffiliate links Β· may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice β€” pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from β€” great next to the visualizers.See the books

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.