-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (91 loc) · 3.21 KB
/
javascript-workflow.yml
File metadata and controls
96 lines (91 loc) · 3.21 KB
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
name: JavaScript workflow
on:
workflow_call:
secrets:
docker_username:
required: false
docker_password:
required: false
argocd_host:
required: false
argocd_password:
required: false
npm_publisher_token:
required: false
inputs:
enable_build:
default: false
type: boolean
enable_tag_latest:
default: false
type: boolean
enable_sync:
default: false
type: boolean
enable_restart:
default: false
type: boolean
image_name:
required: false
type: string
argocd_app:
type: string
required: false
jobs:
build:
name: JavaScript Build
runs-on: ubuntu-latest
steps:
- name: Configure environment
run: |
image_name="${{ github.event.repository.name }}"
if [ -n "${{ inputs.image_name }}" ]; then
image_name="${{ inputs.image_name }}"
fi
lowercase_image_name="${image_name,,}"
echo "IMAGE_NAME=${lowercase_image_name}" >> $GITHUB_ENV
argocd_app="${lowercase_image_name}"
if [ -n "${{ inputs.argocd_app }}" ]; then
argocd_app="${{ inputs.argocd_app }}"
fi
lowercase_argocd_app="${argocd_app,,}"
echo "ARGOCD_APP=${lowercase_argocd_app}" >> $GITHUB_ENV
- name: Check out code
uses: actions/checkout@v4
- name: Log in to Docker Hub
if: ${{ inputs.enable_build }}
uses: docker/login-action@v3
with:
username: ${{ secrets.docker_username }}
password: ${{ secrets.docker_password }}
- name: Set up Docker Buildx
if: ${{ inputs.enable_build }}
uses: docker/setup-buildx-action@v3
- name: Docker build and push
if: ${{ inputs.enable_build }}
run: |
# Branch or tag name with / replaced by __
ref_name_tag="$(echo "${{ github.ref_name }}" | sed 's@/@__@g')"
tags="-t aukilabs/${IMAGE_NAME}:${{ github.sha }} -t aukilabs/${IMAGE_NAME}:${ref_name_tag}"
test "${{ inputs.enable_tag_latest }}" = "true" && tags="${tags} -t aukilabs/${IMAGE_NAME}:latest"
next_build_args="--build-arg NEXT_PUBLIC_AMPLITUDE_API_KEY=__NEXT_PUBLIC_AMPLITUDE_API_KEY__"
docker buildx create --use
docker buildx build $next_build_args --platform linux/amd64 $tags --push .
- name: Authenticate ArgoCD
uses: clowdhaus/argo-cd-action@v2.3.0
if: ${{ inputs.enable_sync || inputs.enable_restart }}
with:
command: login
options: --username admin --password "${{ secrets.argocd_password }}" --grpc-web "${{ secrets.argocd_host }}:443"
- name: Sync ArgoCD app
uses: clowdhaus/argo-cd-action@v2.3.0
if: ${{ inputs.enable_sync }}
with:
command: app sync "${{ env.ARGOCD_APP }}"
options: --grpc-web --async
- name: Restart ArgoCD app
uses: clowdhaus/argo-cd-action@v2.3.0
if: ${{ inputs.enable_restart }}
with:
command: app actions run "${{ env.ARGOCD_APP }}" restart
options: --kind Deployment --resource-name "${{ env.ARGOCD_APP }}" --grpc-web