-
Notifications
You must be signed in to change notification settings - Fork 628
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add build and deploy actions (#650)
- Loading branch information
1 parent
a24cef0
commit 0155be5
Showing
2 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }} |