-
Notifications
You must be signed in to change notification settings - Fork 26
129 lines (111 loc) · 4.79 KB
/
reusable-content-sync.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
##################################################################################
# About
##################################################################################
# Reuseable workflow to be called from content repos.
# Syncs content from Google Drive and creates a pull request. Can be run
# manually by users with access to actions without the need to use git or vscode.
# Needs gdrive credentails set up on repository and a PAT for the pull request
#
# Version : 1.0
#
##################################################################################
# Configuration
##################################################################################
env:
DEPLOYMENT_NAME: ${{vars.DEPLOYMENT_NAME}}
APP_CODE_BRANCH: ${{vars.APP_CODE_BRANCH}}
PARENT_DEPLOYMENT_REPO: ${{vars.PARENT_DEPLOYMENT_REPO}}
PARENT_DEPLOYMENT_NAME: ${{vars.PARENT_DEPLOYMENT_NAME}}
PARENT_DEPLOYMENT_BRANCH: ${{vars.PARENT_DEPLOYMENT_BRANCH}}
DEPLOYMENT_PRIVATE_KEY: ${{secrets.DEPLOYMENT_PRIVATE_KEY}}
FIREBASE_CONFIG: ${{secrets.FIREBASE_CONFIG}}
GDRIVE_CREDENTIALS: ${{ secrets.GDRIVE_CREDENTIALS }}
GDRIVE_TOKEN: ${{ secrets.GDRIVE_TOKEN }}
name: Perform content sync and create a PR
##################################################################################
# Main Code
##################################################################################
on:
workflow_call:
inputs:
pr-title:
description: Title for PR
type: string
default: sync content from google sheets
pr-body:
description: Description for PR
type: string
default: Automated PR creation from actions
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out app code
uses: actions/checkout@v3
with:
repository: "IDEMSInternational/parenting-app-ui.git"
ref: ${{env.APP_CODE_BRANCH}}
- name: Remove .git from the repository in order to nest
run: |
rm -rf .git
- name: Checkout parent repo if needed
if: env.PARENT_DEPLOYMENT_REPO != ''
uses: actions/checkout@v3
with:
path: ".idems_app/deployments/${{env.PARENT_DEPLOYMENT_NAME}}"
repository: ${{env.PARENT_DEPLOYMENT_REPO}}
ref: ${{env.PARENT_DEPLOYMENT_BRANCH}}
- name: Checkout deployment
uses: actions/checkout@v3
with:
token: ${{ secrets.PAT }}
path: ".idems_app/deployments/${{env.DEPLOYMENT_NAME}}"
- name: Populate Encryption key
if: env.DEPLOYMENT_PRIVATE_KEY != ''
run: echo "${{env.DEPLOYMENT_PRIVATE_KEY}}" > ./.idems_app/deployments/${{env.DEPLOYMENT_NAME}}/encrypted/private.key
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Cache node modules
uses: actions/cache@v3
with:
path: ./.yarn/cache
# If cachebusting required (e.g. breaking yarn changes on update) change `v1` to another number
key: ${{ runner.os }}-node-modules-yarn-v1-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-modules-yarn-v1-
- name: Install node modules
run: yarn install
- name: Set deployment
run: yarn workflow deployment set $DEPLOYMENT_NAME
- name: Add google credentials
run: |
echo "${{env.GDRIVE_CREDENTIALS}}" > ./packages/scripts/config/credentials.json
- name: Add google token
run: echo "$GDRIVE_TOKEN" > ./packages/scripts/config/token.json
env:
GDRIVE_TOKEN: ${{ env.GDRIVE_TOKEN }}
- name: Sync content
run: yarn workflow sync
- name: Increment version number
run: yarn scripts version --content --auto-patch
- name: Commit changes
working-directory: .idems_app/deployments/${{env.DEPLOYMENT_NAME}}
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add . # This adds all changes to the staging area
git diff --quiet && git diff --staged --quiet || git commit -m "Automated commit message" # Only commit if there are changes
# git checkout -b automated-changes
- name: Create Pull Request
uses: peter-evans/[email protected]
with:
token: ${{ secrets.PAT }}
# Relative path under $GITHUB_WORKSPACE to the repository. Defaults to $GITHUB_WORKSPACE.
path: .idems_app/deployments/${{env.DEPLOYMENT_NAME}}
# The title of the pull request.
title: ${{ inputs.pr-title }}
# The body of the pull request.
body: ${{ inputs.pr-body }}
labels: test - preview