-
Notifications
You must be signed in to change notification settings - Fork 12
169 lines (147 loc) · 6.14 KB
/
deploy-static-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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: Build mobile artifacts & deploy static content to Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "owntube-build"
cancel-in-progress: false
jobs:
build_info:
runs-on: ubuntu-latest
outputs:
GITHUB_ACTOR: ${{ steps.create.outputs.GITHUB_ACTOR }}
GITHUB_SHA_SHORT: ${{ steps.create.outputs.GITHUB_SHA_SHORT }}
COMMIT_URL: ${{ steps.create.outputs.COMMIT_URL }}
BUILD_TIMESTAMP: ${{ steps.create.outputs.BUILD_TIMESTAMP }}
WEB_URL: ${{ steps.create.outputs.WEB_URL }}
steps:
- id: create
name: "@${{ github.actor }} initiated GitHub Pages deployment, prepare build info"
run: |
# Builder username on GitHub
echo "GITHUB_ACTOR=${{ github.actor }}" && echo "GITHUB_ACTOR=${{ github.actor }}" >> "$GITHUB_OUTPUT"
# Create short Git SHA equivalent to `$(git rev-parse --short HEAD)` e.g. "d1f5cfd"
GITHUB_SHA_SHORT="${GITHUB_SHA::7}"
echo "GITHUB_SHA_SHORT=$GITHUB_SHA_SHORT" && echo "GITHUB_SHA_SHORT=$GITHUB_SHA_SHORT" >> "$GITHUB_OUTPUT"
# Create commit URL, e.g. "https://github.com/OwnTube-tv/web-client/commit/d1f5cfd"
COMMIT_URL="https://github.com/${{ github.repository }}/commit/$GITHUB_SHA_SHORT"
echo "COMMIT_URL=$COMMIT_URL" && echo "COMMIT_URL=$COMMIT_URL" >> "$GITHUB_OUTPUT"
# Create ISO format build timestamp in UTC, e.g. "2024-02-19T13:12:52Z"
BUILD_TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
echo "BUILD_TIMESTAMP=$BUILD_TIMESTAMP" && echo "BUILD_TIMESTAMP=$BUILD_TIMESTAMP" >> "$GITHUB_OUTPUT"
# Extract part after '/' in github.repository
REPO_NAME=$(echo "${{ github.repository }}" | awk -F/ '{print $2}')
echo "REPO_NAME=$REPO_NAME" && echo "REPO_NAME=$REPO_NAME" >> "$GITHUB_OUTPUT"
# Create web url
WEB_URL="https://${{ github.repository_owner }}.github.io/$REPO_NAME"
echo "WEB_URL=$WEB_URL" && echo "WEB_URL=$WEB_URL" >> "$GITHUB_OUTPUT"
code_quality:
needs: build_info
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node 20
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install Dependencies
run: cd OwnTube.tv/ && npm install
- name: Check ESLint Code Style
run: cd OwnTube.tv/ && npx eslint .
- name: Check Prettier Formatting
run: cd OwnTube.tv/ && npx prettier --check ../
- name: Run Tests
run: cd OwnTube.tv/ && npm run test
build_android_apk:
needs: [code_quality, build_info]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node 20
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install Dependencies
run: cd OwnTube.tv/ && npm install
- name: Expo Prebuild android assets
run: cd OwnTube.tv/ && npx expo prebuild --clean --platform android
- name: Set Up JDK
uses: actions/setup-java@v4
with:
distribution: "zulu"
java-version: "17"
cache: "gradle"
- name: Validate Gradle wrapper
uses: gradle/actions/wrapper-validation@v3
- name: Change wrapper permissions
run: cd OwnTube.tv/android/ && chmod +x ./gradlew
- name: Inject Build Info
run: |
# Overwrite build-info.json in source root dir
cat <<EOF > ./OwnTube.tv/build-info.json
{
"GITHUB_ACTOR": "${{ needs.build_info.outputs.GITHUB_ACTOR }}",
"GITHUB_SHA_SHORT": "${{ needs.build_info.outputs.GITHUB_SHA_SHORT }}",
"COMMIT_URL": "${{ needs.build_info.outputs.COMMIT_URL }}",
"BUILD_TIMESTAMP": "${{ needs.build_info.outputs.BUILD_TIMESTAMP }}",
"WEB_URL": "${{ needs.build_info.outputs.WEB_URL }}"
}
EOF
- name: "Build release .apk by @${{ github.actor }}"
run: cd OwnTube.tv/android/ && ./gradlew assembleRelease
- name: Upload .apk artifact
uses: actions/upload-artifact@v4
with:
name: release apk
path: "./OwnTube.tv/android/app/build/outputs/apk/release/app-release.apk"
deploy_web:
needs: [code_quality, build_info]
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node 20
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install Dependencies
run: cd OwnTube.tv/ && npm install
- name: Inject Build Info
run: |
# Overwrite build-info.json in source root dir
cat <<EOF > ./OwnTube.tv/build-info.json
{
"GITHUB_ACTOR": "${{ needs.build_info.outputs.GITHUB_ACTOR }}",
"GITHUB_SHA_SHORT": "${{ needs.build_info.outputs.GITHUB_SHA_SHORT }}",
"COMMIT_URL": "${{ needs.build_info.outputs.COMMIT_URL }}",
"BUILD_TIMESTAMP": "${{ needs.build_info.outputs.BUILD_TIMESTAMP }}",
"WEB_URL": "${{ needs.build_info.outputs.WEB_URL }}"
}
EOF
- name: "Build Web App by @${{ github.actor }}"
run: cd OwnTube.tv/ && cat build-info.json && npx expo export --platform web
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload Expo build output
path: "./OwnTube.tv/dist/"
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4