Skip to content

Instantly share code, notes, and snippets.

@joshraker
Last active September 3, 2023 01:33
Show Gist options
  • Save joshraker/1473c486ab68b4181152d65477fc98ce to your computer and use it in GitHub Desktop.
Save joshraker/1473c486ab68b4181152d65477fc98ce to your computer and use it in GitHub Desktop.
Workflow that creates a tag "release" for a JavaScript GitHub Action after installing `node_modules` so that they don't have to be committed to the main branch.
# Usage: Creates a release with the provided version
# In order to use our JS actions we need to commit node_modules, so we do that
# here and push the result to a version tag for release so that they don't have
# to be committed to the main branch
name: Release
on:
workflow_dispatch:
inputs:
version:
description: Semver version to tag the target with (e.g. 1.2.3)
type: string
required: true
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version-file: .node-version
- name: Install and add node_modules
run: |
# We need node_modules in order to be able to use our JS actions
yarn install --production
git add -f node_modules
- name: Release
run: |
tag='v${{ inputs.version }}'
major_tag="${tag:0:2}"
git config user.name github-actions
git config user.email github-actions@github.com
git commit -m "Release ${tag}"
# Push the specific version tag and update the major version tag
# Start with specific version tag which will error if it's taken
git tag "$tag"
git push origin "$tag"
git tag -f "$major_tag"
git push -f origin "$major_tag"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment