Skip to content

Commit 0155be5

Browse files
authored
ci: add build and deploy actions (#650)
1 parent a24cef0 commit 0155be5

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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 }}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Docker Build and Push
2+
on:
3+
workflow_run:
4+
workflows: ['CI']
5+
branches:
6+
- main
7+
- v2
8+
types:
9+
- completed
10+
11+
env:
12+
REPOSITORY: danielfsousa/express-rest-boilerplate
13+
14+
jobs:
15+
bump-version:
16+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v2
21+
22+
- name: Bump version and push tag
23+
id: tag-version
24+
uses: mathieudutour/[email protected]
25+
with:
26+
github_token: ${{ secrets.GITHUB_TOKEN }}
27+
custom_release_rules: chore:patch:Chores
28+
tag_prefix: ''
29+
30+
- name: Create a GitHub release
31+
uses: actions/create-release@v1
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
with:
35+
tag_name: ${{ steps.tag-version.outputs.new_tag }}
36+
release_name: ${{ steps.tag-version.outputs.new_tag }}
37+
body: ${{ steps.tag-version.outputs.changelog }}
38+
outputs:
39+
tag: ${{ steps.tag-version.outputs.new_tag }}
40+
41+
docker-build-push:
42+
needs: [bump-version]
43+
runs-on: ubuntu-latest
44+
steps:
45+
- name: Checkout
46+
uses: actions/checkout@v2
47+
48+
- name: Update package.json version
49+
run: echo "`jq '.version="${{ env.TAG }}"' package.json`" > package.json
50+
env:
51+
TAG: ${{ needs.bump-version.outputs.tag }}
52+
53+
- name: Set up Docker Buildx
54+
uses: docker/setup-buildx-action@v1
55+
56+
- name: Login to DockerHub
57+
uses: docker/login-action@v1
58+
with:
59+
username: ${{ secrets.DOCKERHUB_USERNAME }}
60+
password: ${{ secrets.DOCKERHUB_TOKEN }}
61+
62+
- name: Build and push
63+
uses: docker/build-push-action@v2
64+
with:
65+
context: .
66+
push: true
67+
tags: ${{ env.REPOSITORY }}:latest,${{ env.REPOSITORY }}:${{ env.TAG }}

0 commit comments

Comments
 (0)