-
Notifications
You must be signed in to change notification settings - Fork 2
138 lines (118 loc) · 5.46 KB
/
trigger_dispatch.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
name: Remote Dispatch Action Responder
on: [repository_dispatch]
jobs:
receive_new_build_job:
name: New IITC Release/Beta/PR build
runs-on: ubuntu-latest
if: github.event.action == 'new_iitc_build'
steps:
- uses: actions/checkout@v3
with:
path: "./website"
token: ${{ secrets.API_TOKEN_GITHUB }}
# git restore-mtime uses the ref log to find the correct timestamp
# for each file. This requires a full git history. The default value (1)
# creates a shallow checkout.
fetch-depth: 0
- name: Setup git config
run: |
cd ./website/
git config user.name "github-actions"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Receive artifact
uses: actions/github-script@v6
with:
script: |
let download = await github.rest.actions.downloadArtifact({
owner: '${{ github.event.client_payload.repo.owner }}',
repo: '${{ github.event.client_payload.repo.repo }}',
artifact_id: '${{ github.event.client_payload.artifact_id }}',
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/build.zip`, Buffer.from(download.data));
- name: Unzip artifact
run: unzip build.zip -d artifact
- name: Set base env
run: |
echo "BUILD_TYPE=$(cat ./artifact/.metadata/build_type)" >> "$GITHUB_ENV"
echo "COMMIT_HASH=$(cat ./artifact/.metadata/commit)" >> "$GITHUB_ENV"
echo "BUILD_APK_FILENAME=$(cat ./artifact/.metadata/apk_filename)" >> "$GITHUB_ENV"
echo "BUILD_ZIP_FILENAME=$(cat ./artifact/.metadata/zip_filename)" >> "$GITHUB_ENV"
echo "BUILDSTAMP=$(cat ./artifact/.metadata/buildstamp)" >> "$GITHUB_ENV"
- name: Set env for Release/Beta/PR build
run: |
if [[ '${{ env.BUILD_TYPE }}' == 'release' ]]; then
echo "TARGET_DIR=build/release_archive/${{ env.BUILDSTAMP }}/" >> "$GITHUB_ENV"
echo "TARGET_APK_FILENAME_FOR_FDROID=IITC-Mobile-Release-${{ env.BUILDSTAMP }}.apk" >> "$GITHUB_ENV"
fi
if [[ '${{ env.BUILD_TYPE }}' == 'beta' ]]; then
echo "TARGET_DIR=build/beta_archive/${{ env.BUILDSTAMP }}/" >> "$GITHUB_ENV"
echo "TARGET_APK_FILENAME_FOR_FDROID=IITC-Mobile-Beta-${{ env.BUILDSTAMP }}.apk" >> "$GITHUB_ENV"
fi
if [[ '${{ env.BUILD_TYPE }}' == 'PR' ]]; then
echo "PR_NUMBER=$(cat ./artifact/.metadata/pr_number)" >> "$GITHUB_ENV"
echo "TARGET_DIR=build/artifact/PR$(cat ./artifact/.metadata/pr_number)/" >> "$GITHUB_ENV"
fi
- name: Restore correct mtime
run: |
sudo apt install git-restore-mtime
cd ./website/
git restore-mtime
- name: Delete old builds
run: |
cd ./website/
ls -trd ./static/build/beta_archive/* | head -n -50 | xargs --no-run-if-empty git rm -r
- name: Copy files to website
run: |
mkdir -p ./website/static/${{ env.TARGET_DIR }}
mkdir -p ./website/static/fdroid/repo/
cp -r ./artifact/build/* ./website/static/${{ env.TARGET_DIR }}
if [[ '${{ env.TARGET_APK_FILENAME_FOR_FDROID }}' != "" ]]; then
cp ./artifact/build/${{ env.BUILD_APK_FILENAME }} ./website/static/fdroid/repo/${{ env.TARGET_APK_FILENAME_FOR_FDROID }}
fi
- name: Set up F-Droid repo secrets
if: ${{ env.BUILD_TYPE != 'PR' }}
run: |
echo "${{ secrets.KEYSTORE_P12 }}" | base64 -d - > ./website/static/fdroid/keystore.p12
echo "${{ secrets.CONFIG_YML }}" | base64 -d - > ./website/static/fdroid/config.yml
- name: Pull F-Droid server and update repo
if: ${{ env.BUILD_TYPE != 'PR' }}
uses: addnab/docker-run-action@v3
with:
image: medzik/fdroidserver:latest
options: -v ${{ github.workspace }}/website/static/fdroid/:/repo
run: |
fdroid update
- name: Save changes
run: |
cd ./website/
rm -rf ./website/static/fdroid/archive
git add -A static/build/ static/fdroid/repo/
- name: Commit and push changes
run: |
cd ./website/
COMMIT_URL="https://github.com/${{ github.event.client_payload.repo.owner }}/${{ github.event.client_payload.repo.repo }}/commit/${{ env.COMMIT_HASH }}"
if [[ '${{ env.BUILD_TYPE }}' == 'PR' ]]; then
git commit -m "🤖 New build PR №${{ env.PR_NUMBER }} from $COMMIT_URL"
else
git commit -m "🤖 New IITC ${{ env.BUILD_TYPE }} build from $COMMIT_URL"
fi
git push origin master
delete_pr_build:
name: Delete PR build
runs-on: ubuntu-latest
if: github.event.action == 'delete_iitc_pr_build'
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.API_TOKEN_GITHUB }}
- name: Setup git config
run: |
git config user.name "github-actions"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Delete old build artifacts
run: |
git rm -r static/build/artifact/PR${{ github.event.client_payload.pr_number }}/
git commit -m "🤖 PR №${{ github.event.client_payload.pr_number }} merged, deleting old build artifacts"
git push origin master