Skip to content

Instantly share code, notes, and snippets.

@Stanko
Last active May 8, 2023 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Stanko/4a0592147e59359f6178ee77921a1153 to your computer and use it in GitHub Desktop.
Save Stanko/4a0592147e59359f6178ee77921a1153 to your computer and use it in GitHub Desktop.

This is a GitHub action we used on several projects to allow our QA team to push changes from dev to qa branch.

Commit list showing commits made by the action

Minimal version

The shorter version does the following:

  • Updates the patch version in package.json on dev
  • Creates new tag
  • Pushes updated files to dev
  • Pushes evertything from dev to qa

Fancier version

The second version does all that, but adds one more thing:

  • Writes package version to version.js file

We then console.log this version on the client. This allows us to open console and be certain which version are we looking at.

import { VERSION } from './version.js';

console.log(`Version: ${VERSION}`);

You'll need to update VERSION_FILE_PATH to point to version.js (you can also switch to .ts)

Notes

  • Action needs to be on your default branch
  • You can run it manually by selecting it in the actions list and then clicking on "Run workflow" button: List of successfull runs of this GitHub action
  • You can use different branch than dev just swap it in the yaml file (screenshot above shows main to qa action).
  • Make sure you leave fetch-depth: '0'. Without it the action won't be able to rebase. I lost a few hours because of this, but luckily I found this Stack Overflow thread.
name: Deploy from DEV to QA
env:
VERSION_FILE_PATH: ./src/js/VERSION_FILE_PATH
on: workflow_dispatch
jobs:
deploy-dev-to-qa:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: 'dev'
fetch-depth: '0'
- name: Update version and deploy to qa branch
run: |
# Init
git config user.name "GitHub Actions"
git config user.email "action@github.com"
# Increase version in package.json
APP_VERSION=$(npm --no-git-tag-version version patch)
# Write version to a JS file
echo "/* DO NOT MAKE EDITS IN THIS FILE!
* This file is automatically by a GitHub action and any changes will be overwritten.
* Check .github/workflows/deploy-to-qa.yaml */
export const VERSION = '$APP_VERSION';" > $VERSION_FILE_PATH
# Commit files and create tag
git add $VERSION_FILE_PATH
git commit ./package.json ./package-lock.json $VERSION_FILE_PATH -m "Increase version to $APP_VERSION"
git tag $APP_VERSION
# Push tag and version update
git push origin dev
git push origin $APP_VERSION
# Finally push everything from dev to qa
git fetch origin qa
git checkout qa
git pull --rebase origin dev
git push origin qa
name: Deploy from DEV to QA
on: workflow_dispatch
jobs:
deploy-dev-to-qa:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: 'dev'
fetch-depth: '0'
- name: Update version and deploy to qa branch
run: |
# Init
git config user.name "GitHub Actions"
git config user.email "action@github.com"
# Increase version in package.json
APP_VERSION=$(npm version patch)
# Push tag and version update
git push origin dev
git push origin $APP_VERSION
# Push everything from dev to qa
git fetch origin qa
git checkout qa
git pull --rebase origin dev
git push origin qa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment