Skip to content

Instantly share code, notes, and snippets.

@mrgarymartin
Created April 7, 2023 16:06
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 mrgarymartin/1670a63a74a6e7c9df01832bd5786e31 to your computer and use it in GitHub Desktop.
Save mrgarymartin/1670a63a74a6e7c9df01832bd5786e31 to your computer and use it in GitHub Desktop.
Github action with rollback.
name: Deploy
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Build application
run: |
npm install
npm run build
- name: Deploy application
run: |
ssh user@server "cd /path/to/application && git pull && npm install && npm run restart"
- name: Create tag
id: tag
run: |
git config --local user.email "action@github.com"
git config --local user.name "Github Action"
git tag deploy-$(date +'%Y%m%d%H%M%S')
git push origin --tags
rollback:
needs: [deploy]
if: startsWith(github.ref, 'refs/tags/rollback-')
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Rollback application
run: |
ssh user@server "cd /path/to/application && git checkout ${GITHUB_SHA} && npm install && npm run restart"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment