-
Notifications
You must be signed in to change notification settings - Fork 125
145 lines (120 loc) · 5.38 KB
/
run.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: CI
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for branch 1 and on start directory, command.txt file changes or by manually running the workflow from actions tab
on:
push:
branches: [ 1 ]
paths:
- 'start/*'
- 'command.txt'
workflow_dispatch:
inputs:
cmdval:
description: 'Command'
required: true
argval:
description: 'Arguments'
required: false
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Partial clone
- name: Partial clone
shell: bash
run: |
REPO="https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git"
git clone --filter=blob:none --no-checkout --depth 1 --sparse $REPO .
git sparse-checkout add start/*
git checkout
- name: Setting the command values from command.txt
if: ${{ github.event_name != 'workflow_dispatch' }}
shell: bash
run: |
echo "::set-env name=mycmd::$(sed -n '1 p' command.txt)"
echo "::set-env name=myargs::$(sed -n '2 p' command.txt)"
- name: Setting the command values using the manually entered values
if: ${{ github.event_name == 'workflow_dispatch' }}
shell: bash
run: |
echo "::set-env name=mycmd::${{ github.event.inputs.cmdval }}"
echo "::set-env name=myargs::${{ github.event.inputs.argval }}"
- name: Print command with args for debug
shell: bash
run: echo ${{ env.mycmd }} ${{ env.myargs }}
- name: Add folders to sparse-checkout only if the command is search or create
if: ${{ contains(env.mycmd, 'create') || contains(env.mycmd, 'search') }}
shell: bash
run: git sparse-checkout add database/linebyline/* isocodes/*
- name: Add folders to sparse-checkout only if the command is fontsgen
if: ${{ contains(env.mycmd, 'fontsgen') }}
shell: bash
run: git sparse-checkout add fonts/*
# Add folders to sparse-checkout
- name: Add folders to sparse-checkout only if the command is update or delete
if: ${{ contains(env.mycmd, 'update') || contains(env.mycmd, 'delete') }}
shell: bash
# delargs gets the arguments in command.txt, then remove start spaces if any, then adds space at end, then replace spaces with *, then remove if only single * exists
# updateargs lists all files in startDir, replaced .txt with * and then replace \n with space
# sparse checkout will have editionName*, which means all files and folders starting with editionName will be checkeout
run: |
delargs=`echo ${{ env.myargs }} | sed -E 's/^\s+//g' | sed -E 's/$/ /g' | sed -E 's/\s+/* /g' | sed -E 's/^\* $//'`
updateargs=`ls -1 start | sed -e 's/\.txt$/*/' | tr '\n' ' '`
git sparse-checkout add isocodes/* $delargs $updateargs
# we need to upgrade the pip ,so we can get the cache directory in muliple os using single command
# we need to upgrade the setuptools ,so that we can install googletrans
- name: Upgrading pip in unix like environments
if: ${{ ! contains(runner.os, 'windows') }}
run: python3 -m pip install --upgrade pip setuptools wheel
shell: bash
- name: Upgrading pip in windows environment
if: ${{ contains(runner.os, 'windows') }}
run: py -3 -m pip install --upgrade pip setuptools wheel
shell: bash
- name: Get cache directories for npm and pip
id: cache-dir
shell: bash
run: |
echo "::set-output name=pipcache::$(pip3 cache dir)"
echo "::set-output name=npmcache::$(npm config get cache)"
- name: Trying to use the old cache if available
uses: actions/cache@v2
with:
path: |
${{ steps.cache-dir.outputs.pipcache }}
${{ steps.cache-dir.outputs.npmcache }}
key: ${{ runner.os }}-cache-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-cache-${{ hashFiles('**/package.json') }}
${{ runner.os }}-cache-${{ hashFiles('**/requirements.txt') }}
${{ runner.os }}-cache-
${{ runner.os }}-
- name: Install Dependencies
run: |
pip3 install -r requirements.txt
npm install
- name: Running the command
run: node apiscript.js ${{ env.mycmd }} ${{ env.myargs }}
# Emptying command.txt as the command from command.txt was already run in previous step
- name: Emptying command.txt
run: |
> command.txt
- name: Saving the log.txt as artifcat
uses: actions/upload-artifact@v2
with:
name: log
path: log.txt
# commiting and pushing changes
- name: commit and push
if: ${{ ! contains(env.mycmd, 'search') }}
shell: bash
run: |
git config --global user.email github-actions@github.com
git config --global user.name github-actions
git add -A
git commit -m ${{ env.mycmd }}
git push