-
Notifications
You must be signed in to change notification settings - Fork 2
163 lines (156 loc) · 6.88 KB
/
build.yaml
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
name: 🤖 Generate Android App
permissions:
contents: write
on:
workflow_dispatch:
inputs:
id:
description: 'Run identifier'
required: true
domain:
description: 'URL of the Website'
required: true
second_domain:
description: 'Second domain (for example files subdomain)'
app_name:
description: 'Name of the App'
required: true
block_media:
description: 'Block images'
type: boolean
default: false
block_ads:
description: 'Block ads'
type: boolean
default: true
view_mode:
description: 'View Mode'
required: true
type: choice
default: 'AUTO'
options:
- 'AUTO'
- 'PORTRAIT'
- 'LANDSCAPE'
icon_url:
description: 'Icon URL'
startup_url:
description: 'Start URL'
no_ssl:
description: 'No SSL - Not recommended!!'
type: boolean
default: false
jobs:
id:
# https://stackoverflow.com/a/73837663
name: Workflow ID Provider
runs-on: ubuntu-latest
steps:
- name: ${{github.event.inputs.id}}
run: echo run identifier ${{ inputs.id }}
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Validate domains
run: |
validate_domain() {
DOMAIN="${1}"
# Remove protocol from URL if present
DOMAIN="${DOMAIN#http://}"
DOMAIN="${DOMAIN#https://}"
DOMAIN="${DOMAIN%%/*}"
if ! [[ $DOMAIN =~ ^[A-Za-z0-9.-]+\.[A-Za-z0-9-]{2,}$ ]]; then
echo "Error: Invalid domain format in $DOMAIN!"
exit 1
fi
echo $DOMAIN
}
# Validate and format primary domain
DOMAIN=$(validate_domain "${{ inputs.domain }}")
echo "PRIMARY_DOMAIN=$DOMAIN" >> $GITHUB_ENV
ALLOWED_DOMAINS="$DOMAIN"
# Validate and add second domain if present
if [ -n "${{ inputs.second_domain }}" ]; then
SECOND_DOMAIN=$(validate_domain "${{ inputs.second_domain }}")
echo "SECOND_DOMAIN=$SECOND_DOMAIN" >> $GITHUB_ENV
ALLOWED_DOMAINS="$ALLOWED_DOMAINS,$SECOND_DOMAIN"
fi
echo "ALLOWED_DOMAINS=$ALLOWED_DOMAINS" >> $GITHUB_ENV
- name: Validate app_name input
run: |
if ! perl -e "exit 1 unless '${{ inputs.app_name }}' =~ /^[:a-zA-Zא-ת0-9 \"_.-]+$/"; then
echo "Error: Invalid app_name format!"
exit 1
fi
- name: Fix applicationId
run: |
# remove all not-allowed characters https://developer.android.com/build/configure-app-module#set-application-id
APPLICATION_ID=$(echo "${{ env.PRIMARY_DOMAIN }}" | perl -pe 's/[^a-zA-Z]//g' | tr '[:upper:]' '[:lower:]')
echo "APPLICATION_ID=com.restictedwebview.$APPLICATION_ID" >> $GITHUB_ENV
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
- name: Create mipmap images
run: |
if [ -n "${{ inputs.icon_url }}" ]; then
npm install && node create_mipmap_images.js "${{ inputs.icon_url }}"
fi
- name: Download AdBlock List
run: curl "https://pgl.yoyo.org/adservers/serverlist.php?hostformat=plain&showintro=1&mimetype=plaintext" -o app/src/main/assets/adblock.txt --create-dirs
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Decode Keystore
id: decode_keystore
uses: timheuer/[email protected]
with:
fileName: 'android_keystore.jks'
fileDir: '/home/runner/work/AndroidRestrictedWebView/AndroidRestrictedWebView/app/keystore/'
encodedString: ${{ secrets.KEYSTORE }}
- name: Build APK
run: ./gradlew assembleRelease
env:
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }}
APPLICATION_ID: ${{ env.APPLICATION_ID }}
APP_NAME: ${{ inputs.app_name }}
VIEW_MODE: ${{ inputs.view_mode }}
STARTUP_URL: ${{ inputs.startup_url }}
ALLOWED_DOMAINS: ${{ env.ALLOWED_DOMAINS }}
BLOCK_MEDIA: ${{ inputs.block_media }}
BLOCK_ADS: ${{ inputs.block_ads }}
NO_SSL: ${{ inputs.no_ssl }}
- name: Rename APK
run: mv app/build/outputs/apk/release/app-release.apk app/build/outputs/apk/release/webview-${{ env.PRIMARY_DOMAIN }}.apk
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ github.run_id }}
name: Release v${{ github.run_id }} (${{ env.PRIMARY_DOMAIN }})
prerelease: true
draft: false
files: app/build/outputs/apk/release/webview-${{ env.PRIMARY_DOMAIN }}.apk
body: |
Restricted WebView App.
Domain: [${{ env.PRIMARY_DOMAIN }}](//${{ env.PRIMARY_DOMAIN }})
Second Domain: [${{ env.SECOND_DOMAIN }}](//${{ env.SECOND_DOMAIN }})
No Secured: ${{ inputs.no_ssl }}
App Name: ${{ inputs.app_name }}
View Mode: ${{ inputs.view_mode }}
Block Media: ${{ inputs.block_media }}
Block Ads: ${{ inputs.block_ads }}
Custom Icon: ${{ inputs.icon_url }}
- name: Get the APK URL
run: |
echo "APK URL: ${{ fromJSON(steps.create_release.outputs.assets)[0].browser_download_url }}"