Skip to content

fix: Fix rollback

fix: Fix rollback #84

Workflow file for this run

name: Deploy to Render
on:
push:
branches:
- fix/github-actions-rollback
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
- name: Install Dependencies
run: yarn install
- name: Copy .env.test to .env
run: cp .env.test .env
- name: Run tests
run: yarn test
- name: Rollback
if: ${{ failure() && github.event_name == 'push' }}
run: |
if [[ "${{ steps.determine_event.outputs.event }}" == "pull_request" ]]; then
git checkout ${{ github.event.pull_request.base.sha }}
elif [[ "${{ steps.determine_event.outputs.event }}" == "push" ]]; then
git checkout ${{ github.event.before }}
else
echo "Unknown event type"
fi
git push --force
# Post a comment on the pull request
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d '{"body": "The CI job has failed. The last commit has been rolled back."}' \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${{ github.event.pull_request.number }}/comments"
deploy:
needs: test
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
- name: Install Dependencies
run: yarn install
- name: Build
run: yarn build
- name: Deploy to Render
uses: johnbeynon/render-deploy-action@v0.0.8
with:
service-id: ${{ secrets.SERVICE_ID_DEVELOP }} # Can be found as part of the Deploy Hook
api-key: ${{ secrets.RENDER_API_KEY }} # Create your API key in Render Dashboard > Account Settings
- name: Rollback
if: ${{ failure() && github.event_name == 'push' }}
run: |
git checkout ${{ github.sha }}^1
git push --force
# Post a comment on the pull request
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d '{"body": "The CI job has failed. The last commit has been rolled back."}' \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${{ github.event.pull_request.number }}/comments"