|
| 1 | +name: Deploy |
| 2 | +on: |
| 3 | + workflow_run: |
| 4 | + workflows: ["Docker Build and Push"] |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - v2 |
| 8 | + types: |
| 9 | + - completed |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + tag: |
| 13 | + description: "Tag (leave empty for latest)" |
| 14 | + required: false |
| 15 | + |
| 16 | +env: |
| 17 | + APP_URL: https://express-rest-boilerplate.onrender.com |
| 18 | + DOCKER_HUB_REPOSITORY: danielfsousa/express-rest-boilerplate |
| 19 | + |
| 20 | +jobs: |
| 21 | + deploy: |
| 22 | + if: ${{ github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == null }} |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@v2 |
| 27 | + with: |
| 28 | + fetch-depth: 0 |
| 29 | + |
| 30 | + - name: Setup Tag |
| 31 | + id: setup-tag |
| 32 | + run: | |
| 33 | + LATEST_TAG=$(git describe --tags --always `git rev-list --tags --max-count=1`) |
| 34 | + INPUT_TAG="${{ github.event.inputs.tag }}" |
| 35 | + DEPLOY_TAG="${INPUT_TAG:-$LATEST_TAG}" |
| 36 | + PREVIOUS_TAG=$(git describe --tags --abbrev=0 $DEPLOY_TAG^) |
| 37 | + echo "DEPLOY_TAG=$DEPLOY_TAG" |
| 38 | + echo ::set-output name=tag::$DEPLOY_TAG |
| 39 | +
|
| 40 | + - uses: chrnorm/deployment-action@releases/v1 |
| 41 | + name: Create GitHub deployment |
| 42 | + id: deployment |
| 43 | + with: |
| 44 | + token: ${{ github.token }} |
| 45 | + target_url: ${{ env.APP_URL }} |
| 46 | + ref: ${{ steps.setup-tag.outputs.tag }} |
| 47 | + environment: production |
| 48 | + |
| 49 | + - name: Deploy to Render.com |
| 50 | + run: curl $DEPLOY_HOOK_URL |
| 51 | + env: |
| 52 | + DEPLOY_HOOK_URL: ${{ secrets.RENDER_DEPLOY_URL }} |
| 53 | + |
| 54 | + - name: Update deployment status (success) |
| 55 | + if: success() |
| 56 | + uses: chrnorm/deployment-status@releases/v1 |
| 57 | + with: |
| 58 | + token: ${{ github.token }} |
| 59 | + target_url: ${{ env.APP_URL }} |
| 60 | + state: success |
| 61 | + deployment_id: ${{ steps.deployment.outputs.deployment_id }} |
| 62 | + |
| 63 | + - name: Update deployment status (failure) |
| 64 | + if: failure() |
| 65 | + uses: chrnorm/deployment-status@releases/v1 |
| 66 | + with: |
| 67 | + token: ${{ github.token }} |
| 68 | + target_url: ${{ env.APP_URL }} |
| 69 | + state: failure |
| 70 | + deployment_id: ${{ steps.deployment.outputs.deployment_id }} |
0 commit comments