diff --git a/.github/workflows/deploy-render.yaml b/.github/workflows/deploy-render.yaml new file mode 100644 index 00000000..2015061d --- /dev/null +++ b/.github/workflows/deploy-render.yaml @@ -0,0 +1,70 @@ +name: Deploy +on: + workflow_run: + workflows: ["Docker Build and Push"] + branches: + - main + - v2 + types: + - completed + workflow_dispatch: + inputs: + tag: + description: "Tag (leave empty for latest)" + required: false + +env: + APP_URL: https://express-rest-boilerplate.onrender.com + DOCKER_HUB_REPOSITORY: danielfsousa/express-rest-boilerplate + +jobs: + deploy: + if: ${{ github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == null }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup Tag + id: setup-tag + run: | + LATEST_TAG=$(git describe --tags --always `git rev-list --tags --max-count=1`) + INPUT_TAG="${{ github.event.inputs.tag }}" + DEPLOY_TAG="${INPUT_TAG:-$LATEST_TAG}" + PREVIOUS_TAG=$(git describe --tags --abbrev=0 $DEPLOY_TAG^) + echo "DEPLOY_TAG=$DEPLOY_TAG" + echo ::set-output name=tag::$DEPLOY_TAG + + - uses: chrnorm/deployment-action@releases/v1 + name: Create GitHub deployment + id: deployment + with: + token: ${{ github.token }} + target_url: ${{ env.APP_URL }} + ref: ${{ steps.setup-tag.outputs.tag }} + environment: production + + - name: Deploy to Render.com + run: curl $DEPLOY_HOOK_URL + env: + DEPLOY_HOOK_URL: ${{ secrets.RENDER_DEPLOY_URL }} + + - name: Update deployment status (success) + if: success() + uses: chrnorm/deployment-status@releases/v1 + with: + token: ${{ github.token }} + target_url: ${{ env.APP_URL }} + state: success + deployment_id: ${{ steps.deployment.outputs.deployment_id }} + + - name: Update deployment status (failure) + if: failure() + uses: chrnorm/deployment-status@releases/v1 + with: + token: ${{ github.token }} + target_url: ${{ env.APP_URL }} + state: failure + deployment_id: ${{ steps.deployment.outputs.deployment_id }} diff --git a/.github/workflows/docker-build-push.yaml b/.github/workflows/docker-build-push.yaml new file mode 100644 index 00000000..bc6636e3 --- /dev/null +++ b/.github/workflows/docker-build-push.yaml @@ -0,0 +1,67 @@ +name: Docker Build and Push +on: + workflow_run: + workflows: ['CI'] + branches: + - main + - v2 + types: + - completed + +env: + REPOSITORY: danielfsousa/express-rest-boilerplate + +jobs: + bump-version: + if: ${{ github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Bump version and push tag + id: tag-version + uses: mathieudutour/github-tag-action@v5.6 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + custom_release_rules: chore:patch:Chores + tag_prefix: '' + + - name: Create a GitHub release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.tag-version.outputs.new_tag }} + release_name: ${{ steps.tag-version.outputs.new_tag }} + body: ${{ steps.tag-version.outputs.changelog }} + outputs: + tag: ${{ steps.tag-version.outputs.new_tag }} + + docker-build-push: + needs: [bump-version] + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Update package.json version + run: echo "`jq '.version="${{ env.TAG }}"' package.json`" > package.json + env: + TAG: ${{ needs.bump-version.outputs.tag }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: ${{ env.REPOSITORY }}:latest,${{ env.REPOSITORY }}:${{ env.TAG }}