-
Notifications
You must be signed in to change notification settings - Fork 41
160 lines (140 loc) · 6.72 KB
/
deploy-main-branches.yml
File metadata and controls
160 lines (140 loc) · 6.72 KB
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
name: Build » Deploy main branches
# NOTE: This should *not* run on tags, these are handled in the main repo
on:
push:
branches:
- develop
- r/*
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
jobs:
detect-repo-owner:
name: Detect branch and appropriate server
if: github.repository_owner == 'opencast'
runs-on: ubuntu-latest
outputs:
server: ${{ steps.test-server.outputs.server }}
branch: ${{ steps.branch-name.outputs.branch }}
steps:
- name: Checkout sources
uses: actions/checkout@v5
- name: Determine the correct test server
id: test-server
run: echo "server=https://`./.github/get-release-server.sh ${{ github.ref_name }}`" >> $GITHUB_OUTPUT
- name: Determine branch name
id: branch-name
run: |
#Temp becomes something like r/17.x
export TEMP=${{ github.ref_name }}
#Strip the r/ prefix, giving us just 17.x. If this is main/develop this does nothing
echo "branch=${TEMP#r\/}" >> $GITHUB_OUTPUT
deploy-main-branches:
name: Deploy admin-interface.opencast.org
runs-on: ubuntu-latest
needs: detect-repo-owner
steps:
- name: Checkout sources
uses: actions/checkout@v5
- name: Get Node.js
uses: actions/setup-node@v5
with:
node-version: 20
- name: Run npm ci
run: npm ci
- name: Build the app
run: |
npm run build
env:
VITE_TEST_SERVER_URL: ${{needs.detect-repo-owner.outputs.server}}
NODE_ENV: development
VITE_TEST_SERVER_AUTH: "admin:opencast"
- name: Prepare git
run: |
git config --global user.name "Admin Interface Deployment Bot"
git config --global user.email "[email protected]"
- name: Commit new version
run: |
# Save the current assets from the main branch
mv .github/assets assets_temp
# Update and change to the gh-pages branch
git fetch --unshallow origin gh-pages
git checkout gh-pages
# Update gh-pages
rm -rf $BRANCH
mv build $BRANCH
#Generate an index, in case anyone lands at the root of the test domain
echo $'<html><head><link rel=stylesheet type=text/css href=assets/index.css /></head><body><div class="head-container"><img src=assets/opencast-white.svg /></div><div class="navbar-container"></div><div class="text-container"><p>Deployment for the latest development versions of the Opencast admin interface.The branches listed here correspond to Opencast\'s own branches.</br><b>Please select a version.</b></p></div><ul>' > index.html
find . -mindepth 1 -maxdepth 1 -type d \
| grep '[0-9]*.x\|develop' \
| sort -r \
| sed 's/^\(.*\)$/<li><a href=\1>\1<\/a><\/li>/' >> index.html
echo '</ul></body></html>' >> index.html
git add $BRANCH index.html
git diff --staged --quiet || git commit --amend -m "Build $(date)"
env:
BRANCH: ${{needs.detect-repo-owner.outputs.branch}}
- name: update CSS and other assets
if: github.ref == 'refs/heads/develop'
run: |
rm -rf assets
mv assets_temp assets
git add assets
git diff --staged --quiet || git commit --amend -m "Build $(date)"
- name: Push updates
run: git push origin gh-pages --force
file-upstream-admin-pr:
name: Create upstream admin PR to incorporate build
runs-on: ubuntu-latest
needs: detect-repo-owner
permissions:
contents: write # For the release
pull-requests: write # For the PR in the upstream repo
steps:
- name: Prepare git
run: |
git config --global user.name "Admin Interface Commit Bot"
git config --global user.email "[email protected]"
- name: Prepare GitHub SSH key
env:
DEPLOY_KEY: ${{ secrets.MODULE_PR_DEPLOY_KEY }}
run: |
install -dm 700 ~/.ssh/
echo "${DEPLOY_KEY}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan github.com >> ~/.ssh/known_hosts
- name: Clone upstream repository
run: |
git clone -b ${{ github.ref_name }} "[email protected]:${{ github.repository_owner }}/opencast.git" opencast
cd opencast
git checkout -b t/admin-${{ needs.detect-repo-owner.outputs.branch }}
- name: Update the admin submodule
working-directory: opencast
run: |
# Note: This could be a race condition in that rapid submodule pushes can trigger multiple PRs in short order
# and we don't have a guarantee that the update triggered by commit A does not end up finding commit B
# We are going to ignore this possibility since we almost universally want the *latest* commit, though this
# could end up causing the commit message, and the actual submodule hash to differ.
git submodule update --init --remote modules/admin
git add modules/admin
git commit -m "Updating admin-service to ${{ github.sha }}"
# This token is an account wide token which allows creation of PRs and pushes.
echo "${{ secrets.MODULE_PR_TOKEN }}" > token.txt
gh auth login --with-token < token.txt
export CURRENT_PR=$(gh pr list -R ${{ github.repository_owner }}/opencast --head t/admin-${{ needs.detect-repo-owner.outputs.branch }} --json number --jq '.[].number')
git push origin t/admin-${{ needs.detect-repo-owner.outputs.branch }} --force
if [ -n "$CURRENT_PR" ]; then
gh pr edit $CURRENT_PR \
--body "Updating Opencast ${{ needs.detect-repo-owner.outputs.branch }} Admin Interface module to [${{ github.sha }}](https://github.com/${{ github.repository_owner }}/admin-interface/commit/${{ github.sha }})" \
-R ${{ github.repository_owner }}/opencast
else
gh pr create \
--title "Update ${{ needs.detect-repo-owner.outputs.branch }} Admin Interface" \
--body "Updating Opencast ${{ needs.detect-repo-owner.outputs.branch }} Admin Interface module to [${{ github.sha }}](https://github.com/${{ github.repository_owner }}/admin-interface/commit/${{ github.sha }})" \
--head=${{ github.repository_owner }}:t/admin-${{ needs.detect-repo-owner.outputs.branch }} \
--base ${{ github.ref_name }} \
-R ${{ github.repository_owner }}/opencast
#FIXME: fine grained PATs can't apply labels
#FIXME: classic PATs don't have the permissions because the PR isn't in an opencastproject (the user) repo
#--label admin-ui --label maintenance \
fi