Interview Prep/CI/CD/GitHub Actions

How do you create a release and publish packages from GitHub Actions?

IntermediateConceptGitHub Actions
Answer

Trigger on a version tag, build, then create a GitHub Release with gh release create and publish to GHCR/npm with the built-in token.

on:
  push:
    tags: ['v*.*.*']
permissions:
  contents: write
  packages: write
jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
      - run: |
          docker build -t ghcr.io/${{ github.repository }}:${{ github.ref_name }} .
          docker push ghcr.io/${{ github.repository }}:${{ github.ref_name }}
      - run: gh release create "${{ github.ref_name }}" --generate-notes
        env: { GH_TOKEN: '${{ github.token }}' }
All CI/CD questions

More on GitHub Actions