-
Notifications
You must be signed in to change notification settings - Fork 0
105 lines (92 loc) · 3.37 KB
/
deploy.yml
File metadata and controls
105 lines (92 loc) · 3.37 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
97
98
99
100
101
102
103
104
105
name: Build and Deploy
on:
workflow_call:
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Check Out Repo
uses: actions/checkout@v2
- name: Set repo name
id: repo
run: |
echo "REPO=$(echo ${{ github.repository }} | cut -d'/' -f2 | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Set container name
id: container
run: |
if [[ "${{ github.workflow }}" == "Land" ]]; then
echo "CONTAINER=$(echo $REPO | cut -d'/' -f2 | tr '.' '-')-land" >> $GITHUB_ENV
elif [[ "${{ github.workflow }}" == "Deploy" ]]; then
echo "CONTAINER=$(echo $REPO | cut -d'/' -f2 | tr '.' '-')-live" >> $GITHUB_ENV
else
echo "Invalid workflow name for use this workflow. Please use either "Land" or "Deploy" as workflow name"
exit 1
fi
- name: Set image tag
id: tag
run: |
if [[ "${{ github.workflow }}" == "Land" ]]; then
echo "TAG=land-${{ github.run_id }}" >> $GITHUB_ENV
elif [[ "${{ github.workflow }}" == "Deploy" ]]; then
echo "TAG=latest-${{ github.run_id }}" >> $GITHUB_ENV
else
echo "Invalid workflow name for use this workflow. Please use either "Land" or "Deploy" as workflow name"
exit 1
fi
- name: Get repo topics
id: get_topics
run: |
TOKEN=${{ secrets.GITHUB_TOKEN }}
REPO=${{ github.repository }}
RESPONSE=$(curl -s -H "Accept: application/vnd.github.mercy-preview+json" -H "Authorization: token $TOKEN" https://api.github.com/repos/$REPO/topics)
TOPICS=$(echo $RESPONSE | jq -r '.names[]' | tr '\n' ',')
echo "Repo topics are $TOPICS"
echo "TOPICS=$TOPICS" >> $GITHUB_ENV
- name: Get branch name
id: get_branch
run: |
BRANCH=$(echo ${{ github.ref }} | cut -d'/' -f3)
echo "Branch is $BRANCH"
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
- name: Print Repo Info
run: |
echo "Repo: $REPO"
echo "Container: $CONTAINER"
echo "Tag: $TAG"
echo "Topics: $TOPICS"
echo "Branch: $BRANCH"
- name: Set config file
if: ${{!contains(env.TOPICS, 'website')}}
run: |
if [[ "${{ github.workflow }}" == "Land" ]]; then
cp config.land.js config.js
elif [[ "${{ github.workflow }}" == "Deploy" ]]; then
cp config.live.js config.js
fi
- name: Update version.json
if: ${{!contains(env.TOPICS, 'website')}}
run: |
echo "{ \"version\": \"$BRANCH\" }" > ./src/version.json
- name: Install Dependencies
run: npm ci
- name: Build
if: ${{!contains(env.TOPICS, 'node')}}
run: npm run build
- name: Log in to Docker Hub
env:
DOCKER_ACCESS_TOKEN: ${{ secrets.DOCKER_ACCESS_TOKEN }}
uses: docker/login-action@v1
with:
username: canmingir
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
- name: Build and Push Docker Image
uses: docker/build-push-action@v2
with:
push: true
tags: |
canmingir/${{env.REPO}}:latest
canmingir/${{env.REPO}}:${{env.TAG}}
context: .