-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
101 lines (89 loc) · 3.29 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: Deploy to DigitalOcean
description: Build docker images and push to the DigitalOcean registry
inputs:
github-token:
description: 'Github personal access token with read repo rights'
required: true
digital-ocean-access-token:
description: 'The DIGITALOCEAN_API_TOKEN secret'
required: true
node-version:
description: 'The node version to install the node modules with'
required: false
default: 21.x
cms:
description: 'Wether or not the project contains a CMS'
required: false
runs:
using: composite
steps:
- uses: actions/checkout@v4
- uses: digitalocean/action-doctl@v2
with:
token: ${{ inputs.digital-ocean-access-token }}
- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version || '21.x' }}
cache: "npm"
cache-dependency-path: "./app/package-lock.json"
- name: login to digitalocean registry
shell: bash
run: doctl registry login
- name: Build app
shell: bash
env:
APP_IMAGE: registry.digitalocean.com/${{ github.repository }}:app-${{ github.ref_type == 'tag' && github.ref_name || 'latest' }}
run: |
cd ./app
npm ci --include=dev
npm run build
npm prune --omit=dev
cd ..
docker build -t $APP_IMAGE ./app
docker push $APP_IMAGE
- name: Cache Composer dependencies
if: ${{ inputs.cms }}
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: composer-${{ hashFiles('**/composer.lock') }}
- name: Install Composer dependencies
if: ${{ inputs.cms }}
uses: php-actions/composer@v6
env:
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ inputs.github-token }}"} }'
with:
dev: no
progress: yes
working_dir: "cms"
args: --ignore-platform-reqs --prefer-dist
- name: Build cms
if: ${{ inputs.cms }}
shell: bash
env:
CMS_IMAGE: registry.digitalocean.com/${{ github.repository }}:cms-${{ github.ref_type == 'tag' && github.ref_name || 'latest' }}
run: |
docker build -t $CMS_IMAGE ./cms
docker push $CMS_IMAGE
- name: Build cms-cli
if: ${{ inputs.cms }}
shell: bash
env:
CMS_CLI_IMAGE: registry.digitalocean.com/${{ github.repository }}:cms-cli-${{ github.ref_type == 'tag' && github.ref_name || 'latest' }}
run: |
docker build -f ./cms/cli.Dockerfile -t $CMS_CLI_IMAGE ./cms
docker push $CMS_CLI_IMAGE
- name: Update DigitalOcean App tags
if: github.ref_type == 'tag'
shell: bash
run: |
repository=$(echo ${{ github.repository }} | sed -E "s/born05\///")-prd
app_id=$(doctl apps list | grep $repository | awk '{print $1}')
doctl apps spec get $app_id | sed -E "/tag: (cms|cms-cli|app)/ s/[0-9]+.[0-9]+.[0-9]+/${{ github.ref_name }}/" | sed -E "/key: VERSION$/,+2 s/value: .*/value: ${{ github.ref_name }}/" | doctl apps update $app_id --spec=-
- name: Create new deployment
if: github.ref_name == 'main' || github.ref_name == 'master'
shell: bash
run: |
repository=$(echo ${{ github.repository }} | sed -E "s/born05\///")-acc
app_id=$(doctl apps list | grep $repository | awk '{print $1}')
doctl apps create-deployment $app_id