Created
April 7, 2023 16:06
-
-
Save mrgarymartin/1670a63a74a6e7c9df01832bd5786e31 to your computer and use it in GitHub Desktop.
Github action with rollback.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "[email protected]" | |
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