1+ name : Publish Theia IDE Preview Deployment
2+
3+ permissions :
4+ contents : read
5+ pull-requests : write
6+
7+ on :
8+ workflow_dispatch :
9+ inputs :
10+ tag :
11+ description : The image's tag
12+ required : true
13+ default : next
14+ theia_version :
15+ description : Theia Version
16+ required : false
17+ default : next
18+
19+ pull_request :
20+ branches : [master]
21+ types :
22+ - opened
23+ - synchronize
24+ - reopened
25+
26+ schedule :
27+ - cron : ' 0 13 * * 0'
28+
29+ concurrency :
30+ group : ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
31+ cancel-in-progress : true
32+
33+ jobs :
34+ build :
35+ name : Build Theia IDE Preview image
36+ runs-on : ubuntu-latest
37+
38+ steps :
39+ - name : Checkout
40+ uses : actions/checkout@v2
41+
42+ - name : Use Node.js 20.x
43+ uses : actions/setup-node@v3
44+ with :
45+ node-version : 20.x
46+ registry-url : ' https://registry.npmjs.org'
47+
48+ - name : Use Python 3.11
49+ uses : actions/setup-python@v4
50+ with :
51+ python-version : ' 3.11'
52+
53+ - name : Install dependencies for native-keymap
54+ run : sudo apt-get update && sudo apt-get install -y libx11-dev libxkbfile-dev
55+
56+ - name : Set up Docker Buildx
57+ uses : docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1
58+
59+ - name : Set the Theia version
60+ id : set-theia-version
61+ run : |
62+ if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
63+ echo "THEIA_VERSION=${{ github.event.inputs.theia_version }}" >> $GITHUB_ENV
64+ elif [ "${{ github.event_name }}" == "pull_request" ]; then
65+ echo "THEIA_VERSION=" >> $GITHUB_ENV
66+ else
67+ echo "THEIA_VERSION=next" >> $GITHUB_ENV
68+ fi
69+
70+ - name : Run Theia update if version is specified
71+ if : ${{ env.THEIA_VERSION != '' }}
72+ run : |
73+ yarn && yarn update:theia ${THEIA_VERSION} && yarn update:theia:children ${THEIA_VERSION} && yarn
74+
75+ - name : Set image tag
76+ id : set-tag
77+ run : |
78+ if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
79+ echo "IMAGE_TAG=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
80+ elif [ "${{ github.event_name }}" == "pull_request" ]; then
81+ echo "IMAGE_TAG=pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
82+ elif [ "${{ github.event_name }}" == "schedule" ]; then
83+ echo "IMAGE_TAG=weekly" >> $GITHUB_ENV
84+ else
85+ echo "IMAGE_TAG=other" >> $GITHUB_ENV
86+ fi
87+
88+ - name : Authenticate to Google Cloud
89+ uses : google-github-actions/auth@71f986410dfbc7added4569d411d040a91dc6935 # v2.1.8
90+ with :
91+ credentials_json : ${{ secrets.GCP_SA_KEY }}
92+ project_id : kubernetes-238012
93+ create_credentials_file : true
94+
95+ - name : Setup Google Cloud SDK
96+ uses : google-github-actions/setup-gcloud@77e7a554d41e2ee56fc945c52dfd3f33d12def9a # v2.1.4
97+
98+ - name : Configure Docker for Artifact Registry
99+ run : |
100+ gcloud auth configure-docker europe-west3-docker.pkg.dev
101+
102+ - name : Update bot comment
103+ if : github.event_name == 'pull_request'
104+ uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # 7.0.1
105+ with :
106+ script : |
107+ const {data: comments} = await github.rest.issues.listComments({
108+ owner: context.repo.owner,
109+ repo: context.repo.repo,
110+ issue_number: context.payload.number,
111+ })
112+ const botComment = comments.find(comment => comment.user.id === 41898282)
113+ const commentBody = "Thank you for opening the PR!\n\nThis comment will be replaced with a link to a Preview deployment as soon as it is ready."
114+ if (botComment) {
115+ await github.rest.issues.updateComment({
116+ owner: context.repo.owner,
117+ repo: context.repo.repo,
118+ comment_id: botComment.id,
119+ body: commentBody
120+ })
121+ } else {
122+ await github.rest.issues.createComment({
123+ owner: context.repo.owner,
124+ repo: context.repo.repo,
125+ issue_number: context.payload.number,
126+ body: commentBody
127+ })
128+ }
129+
130+ - name : Build Docker image
131+ uses : docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 # v6.10.0
132+ with :
133+ context : .
134+ file : browser.Dockerfile
135+ push : true
136+ tags : |
137+ europe-west3-docker.pkg.dev/kubernetes-238012/theia-ide-preview/theia-ide-preview:${{ env.IMAGE_TAG }}
138+
139+ - name : Get GKE Credentials
140+ uses : google-github-actions/get-gke-credentials@d0cee45012069b163a631894b98904a9e6723729 # v2.3.3
141+ with :
142+ cluster_name : github-theia-ide-preview
143+ location : europe-west3-c
144+
145+ - name : List sessions in theia-cloud namespace
146+ run : kubectl get sessions -n theia-cloud
147+
148+ - name : List apps in theia-cloud namespace
149+ run : kubectl get appdefinitions -n theia-cloud
150+
151+ - name : Delete app definition if existent
152+ run : kubectl delete appdefinitions theia-ide-${{ env.IMAGE_TAG }} -n theia-cloud || true
153+
154+ - name : Delete existing sessions
155+ run : kubectl get sessions -n theia-cloud -o json | jq -r '.items[] | select(.spec.appDefinition == "theia-ide-${{ env.IMAGE_TAG }}") | .metadata.name' | xargs -r kubectl delete sessions -n theia-cloud
156+
157+ - name : Create app definition
158+ run : |
159+ cat <<EOF | kubectl apply -f -
160+ apiVersion: theia.cloud/v1beta10
161+ kind: AppDefinition
162+ metadata:
163+ name: theia-ide-${{ env.IMAGE_TAG }}
164+ namespace: theia-cloud
165+ spec:
166+ downlinkLimit: 30000
167+ image: europe-west3-docker.pkg.dev/kubernetes-238012/theia-ide-preview/theia-ide-preview:${{ env.IMAGE_TAG }}
168+ imagePullPolicy: Always
169+ ingressname: theia-cloud-demo-ws-ingress
170+ limitsCpu: "2"
171+ limitsMemory: 500M
172+ maxInstances: 3
173+ minInstances: 0
174+ mountPath: /home/project/persisted
175+ name: theia-ide-${{ env.IMAGE_TAG }}
176+ port: 3000
177+ requestsCpu: "100m"
178+ requestsMemory: 300M
179+ timeout: 15
180+ uid: 101
181+ uplinkLimit: 30000
182+ EOF
183+
184+ - name : Update bot comment with URL
185+ if : github.event_name == 'pull_request'
186+ uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # 7.0.1
187+ with :
188+ script : |
189+ const {data: comments} = await github.rest.issues.listComments({
190+ owner: context.repo.owner,
191+ repo: context.repo.repo,
192+ issue_number: context.payload.number,
193+ })
194+ const botComment = comments.find(comment => comment.user.id === 41898282)
195+ const commentBody = "Preview deployment created at https://launch.theia-ide-preview.eclipsesource-munich.com/?appDef=theia-ide-${{ env.IMAGE_TAG }}\n\nWhen the deployment is cleaned up, this link will be removed again."
196+ if (botComment) {
197+ await github.rest.issues.updateComment({
198+ owner: context.repo.owner,
199+ repo: context.repo.repo,
200+ comment_id: botComment.id,
201+ body: commentBody
202+ })
203+ } else {
204+ await github.rest.issues.createComment({
205+ owner: context.repo.owner,
206+ repo: context.repo.repo,
207+ issue_number: context.payload.number,
208+ body: commentBody
209+ })
210+ }
0 commit comments