Skip to content

Instantly share code, notes, and snippets.

@JonDotsoy
Last active June 7, 2024 14:43
Show Gist options
  • Save JonDotsoy/82e761e900ba9bdd30588b50113457b1 to your computer and use it in GitHub Desktop.
Save JonDotsoy/82e761e900ba9bdd30588b50113457b1 to your computer and use it in GitHub Desktop.
This GitHub Actions workflow automates the release process. When changes are pushed to the "develop" branch, it uses Release Please to generate release notes and create a GitHub release. If a release is created, it then sets up the Node.js environment and publishes the package to npm.
on:
push:
branches:
- "develop"
name: Release
permissions:
contents: write
pull-requests: write
jobs:
release-please:
runs-on: ubuntu-latest
outputs:
release_created: ${{ steps.release-please.outputs.release_created }}
steps:
- uses: googleapis/release-please-action@v4
id: release-please
with:
token: ${{ secrets.GITHUB_TOKEN }}
publish:
runs-on: ubuntu-latest
needs: release-please
if: ${{ needs.release-please.outputs.release_created }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
registry-url: "https://registry.npmjs.org"
- uses: oven-sh/setup-bun@v1
- run: bun i
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

The script .github/workflows/release.yaml is a GitHub Actions workflow configuration file that automates the release process for a project. Here's a breakdown of its components and steps:

Overview

  • Trigger: The workflow is triggered by a push to the "develop" branch.
  • Workflow Name: "Release"
  • Permissions: Grants write permissions for contents and pull-requests.

Jobs

The workflow consists of two jobs: release-please and publish.

1. release-please Job

  • Runs-on: ubuntu-latest (the job will run on the latest Ubuntu runner).
  • Outputs: Captures the output release_created from the release-please step.

Steps:

  1. Uses release-please-action:
    • Action: googleapis/release-please-action@v4
    • ID: release-please
    • With: token: ${{ secrets.GITHUB_TOKEN }}
    • Purpose: This step uses Google's Release Please action to automate the release process, including generating release notes and creating a GitHub release. It outputs whether a release was created.

2. publish Job

  • Runs-on: ubuntu-latest
  • Needs: This job depends on the release-please job.
  • Condition: This job will only run if the release_created output from the release-please job is true (${{ needs.release-please.outputs.release_created }}).

Steps:

  1. Checkout the Repository:

    • Action: actions/checkout@v4
    • Purpose: Checks out the repository code.
  2. Setup Node.js:

    • Action: actions/setup-node@v4
    • With:
      • node-version: 22
      • registry-url: "https://registry.npmjs.org"
    • Purpose: Sets up Node.js environment for version 22 and configures the npm registry URL.
  3. Setup Bun:

    • Action: oven-sh/setup-bun@v1
    • Purpose: Sets up Bun, a fast JavaScript runtime.
  4. Install Dependencies:

    • Command: bun i
    • Purpose: Installs project dependencies using Bun.
  5. Publish to npm:

    • Command: npm publish
    • Environment Variable: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
    • Purpose: Publishes the package to the npm registry using the npm token for authentication.

Summary

This workflow automates the release process by using Release Please to manage the creation of releases and publishing the package to npm when a new release is created. The process ensures that releases are consistently managed and published whenever changes are pushed to the "develop" branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment