-
Notifications
You must be signed in to change notification settings - Fork 3
132 lines (115 loc) · 4.49 KB
/
main.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
# Name of the GitHub Actions Workflow
name: Build and deploy to GitHub Pages
# Triggers for the Workflow
on:
push:
branches:
- master # Trigger the workflow on push events to the main branch
schedule:
- cron: '0 0 * * 1' # Run dependency updates weekly on Monday at 00:00
workflow_dispatch:
jobs:
build-and-deploy:
runs-on: ubuntu-latest # The type of runner that the job will run on
steps:
# Checks out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout Repository
uses: actions/checkout@v3
# Sets up a Node.js environment using the version specified in .nvmrc
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
# Caches dependencies for faster subsequent runs
- name: Cache Node Modules
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
# Performs security scanning to identify known vulnerabilities in dependencies
- name: Security Scanning
run: |
npm install
npm audit --production # Focuses on production dependencies
continue-on-error: true # Allows the workflow to continue even if vulnerabilities are found
- name: Install Buf
run: |
curl -sSL \
"https://github.com/bufbuild/buf/releases/latest/download/buf-Linux-x86_64" \
-o /usr/local/bin/buf
chmod +x /usr/local/bin/buf
# Install Go and protoc-gen-typescript-http
- name: Install Go and protoc-gen-typescript-http
run: |
sudo add-apt-repository ppa:longsleep/golang-backports -y
sudo apt-get update
sudo apt-get install golang-go -y
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
go install go.einride.tech/protoc-gen-typescript-http@latest
echo "GOPATH=$GOPATH" >> $GITHUB_ENV
echo "PATH=$PATH:$GOPATH/bin" >> $GITHUB_ENV
# Custom step to prepare your code for the build process
- name: Prepare the Code for Build
run: make init
# Builds your React application
- name: Build React Application
env:
REACT_APP_SERVER_URL: ${{ secrets.SERVER_URL }} # Uses a secret for the server URL
run: |
echo "REACT_APP_SERVER_URL=${{ secrets.SERVER_URL }}" > .env
yarn install
yarn build
# Deploys the built site to GitHub Pages
- name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages # Specifies the deployment branch
folder: dist # Specifies the folder to deploy
clean: true # Ensures a clean deployment
# Sends a success notification to Telegram if deployment succeeds
- name: Notification for Success
if: success()
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_CHAT_ID }}
token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
message: Deployment to GitHub Pages succeeded!
# Sends a failure notification to Telegram if deployment fails
- name: Notification for Failure
if: failure()
uses: appleboy/telegram-action@master
with:
to: ${{ secrets.TELEGRAM_CHAT_ID }}
token: ${{ secrets.TELEGRAM_BOT_TOKEN }}
message: Deployment to GitHub Pages failed. Please check the Actions log.
# Job for updating dependencies on a schedule
update-dependencies:
runs-on: ubuntu-latest
if: github.event_name == 'schedule' # Only runs for scheduled events
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
- name: Cache Node Modules
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
# Updates all dependencies in package.json to their latest versions
- name: Update Dependencies
run: |
npm install -g npm-check-updates
ncu -u
npm install
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git commit -am "Update dependencies" --allow-empty # Commits changes if there are any
git push