Skip to content

Commit db49ca7

Browse files
committed
add workflows
1 parent 0dda223 commit db49ca7

File tree

3 files changed

+252
-0
lines changed

3 files changed

+252
-0
lines changed

.github/workflows/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM ocaml/opam:ubuntu-lts-ocaml-4.14
2+
3+
USER root
4+
RUN dpkg --add-architecture i386 && \
5+
apt-get update --fix-missing -y && \
6+
apt-get install -y software-properties-common gcc-multilib make m4 && \
7+
rm -rf /var/lib/apt/lists/*
8+
9+
USER opam
10+
RUN opam init --disable-sandboxing -y && \
11+
eval $(opam env) && \
12+
opam pin add Lama https://github.com/PLTools/Lama.git\#1.30 --no-action && \
13+
opam install -y Lama

.github/workflows/cache_docker.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Cache Lama Docker Image
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * *"
6+
push:
7+
branches:
8+
- main
9+
10+
jobs:
11+
check-cache:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
cache_found: ${{ steps.step1.outputs.noCache }}
15+
steps:
16+
- name: Retrieve Docker image
17+
uses: actions/cache/restore@v3
18+
with:
19+
path: lama-1-30.tar
20+
key: lama-1-30-${{ runner.os }}-
21+
22+
- name: Check if Lama-docker was restored from cache
23+
id: step1
24+
run: |
25+
if [ -f lama-1-30.tar ]; then
26+
echo "Lama's docker image is restored successfully. Exiting..."
27+
echo "noCache=true" >> $GITHUB_OUTPUT
28+
else
29+
echo "Cache not found. Building.."
30+
echo "noCache=false" >> $GITHUB_OUTPUT
31+
fi
32+
33+
build-image:
34+
needs: [check-cache]
35+
if: needs.check-cache.outputs.cache_found != 'true'
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Checkout repository
39+
uses: actions/checkout@v3
40+
- name: Set up Docker Buildx
41+
uses: docker/setup-buildx-action@v3
42+
43+
- name: Build Docker image
44+
uses: docker/build-push-action@v5
45+
with:
46+
context: .
47+
file: ./.github/workflows/Dockerfile
48+
tags: berezun/lama-image:latest
49+
outputs: type=docker,dest=lama-1-30.tar
50+
51+
- name: Cache Docker Lama file
52+
id: cache-file
53+
uses: actions/cache/save@v3
54+
with:
55+
path: lama-1-30.tar
56+
key: lama-1-30-${{ runner.os }}-
57+
restore-keys: |
58+
lama-1-30-${{ runner.os }}-

.github/workflows/postaction.yml

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
name: PostAction
2+
3+
on:
4+
workflow_run:
5+
workflows: ["CheckPullRequest"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
job2:
11+
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}
12+
runs-on: ubuntu-latest
13+
outputs:
14+
output_id_number: ${{ steps.step1.outputs.id }}
15+
update_is_needed: ${{ steps.step1.outputs.update_is_needed }}
16+
steps:
17+
- name: 'Download artifact'
18+
uses: actions/github-script@v6
19+
with:
20+
script: |
21+
console.log(${{ github.event.workflow_run.id }});
22+
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
23+
owner: context.repo.owner,
24+
repo: context.repo.repo,
25+
run_id: ${{ github.event.workflow_run.id }},
26+
});
27+
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
28+
return artifact.name == "share_info";
29+
})[0];
30+
var download = await github.rest.actions.downloadArtifact({
31+
owner: context.repo.owner,
32+
repo: context.repo.repo,
33+
artifact_id: matchArtifact.id,
34+
archive_format: 'zip',
35+
});
36+
var fs = require('fs');
37+
fs.writeFileSync('${{ github.workspace }}/share_info.zip', Buffer.from(download.data));
38+
39+
- run: unzip share_info.zip
40+
- run: |
41+
echo "university=$(cat university.txt)" >> $GITHUB_ENV
42+
echo "assignment=$(cat assignment_number.txt)" >> $GITHUB_ENV
43+
echo "login=$(cat gitid.txt)" >> $GITHUB_ENV
44+
echo "base=$(cat base.txt)" >> $GITHUB_ENV
45+
- id: 'get_deadlines_worksheet'
46+
uses: jroehl/gsheet.action@v2.1.1
47+
with:
48+
spreadsheetId: ${{secrets.SPREADSHEET_ID}}
49+
commands: | # list of commands, specified as a valid JSON string
50+
[
51+
{ "command": "getData", "args": { "worksheetTitle": "Deadlines", "minCol": 1, "maxCol": 20 } }
52+
]
53+
env:
54+
GSHEET_CLIENT_EMAIL: ${{ secrets.SERVICE_EMAIL }}
55+
GSHEET_PRIVATE_KEY: ${{ secrets.SERVICE_KEY }}
56+
- id: check-deadline
57+
name: check-deadline
58+
env:
59+
RESULTS: ${{ steps.get_deadlines_worksheet.outputs.results }}
60+
run: |
61+
cmd=$(echo "${RESULTS}" | jq ".results[0].result.rawData")
62+
assignment=${{ env.assignment }}
63+
university="\"${{ env.university }}\""
64+
# Find Deadline in the Google Sheet
65+
row=0
66+
for j in {1..10}
67+
do
68+
t=$(echo "${cmd}" | jq ".[$j][0]")
69+
if [ $t = $university ]; then
70+
echo "university FOUND: $j"
71+
row=$j
72+
echo $row
73+
break
74+
fi
75+
done
76+
if [ $row -eq 0 ]; then
77+
echo "ERROR: Deadline for $university not found!"
78+
exit 1
79+
fi
80+
deadline=$(echo "${cmd}" | jq ".[$row][${assignment}]")
81+
echo "Deadline for $university for assignment number $assignment is $deadline"
82+
# Get submission time
83+
submission_time="\"${{ github.event.workflow_run.head_commit.timestamp }}\""
84+
# Check Deadline
85+
echo $submission_time
86+
echo $deadline
87+
if [[ $submission_time > $deadline ]]; then
88+
echo "result=0.01" >> $GITHUB_ENV
89+
echo "FIASCO: The deadline has expired"
90+
else
91+
echo "result=1" >> $GITHUB_ENV
92+
echo "OK: you are on time!"
93+
fi
94+
95+
# - name: Check out code
96+
# uses: actions/checkout@v2
97+
# - name: Comment PR
98+
# uses: thollander/actions-comment-pull-request@v2
99+
# with:
100+
# message: |
101+
# All checks have successfully passed!
102+
# The assignment is submitted on time.
103+
# reactions: rocket
104+
105+
- id: 'get_worksheet'
106+
uses: jroehl/gsheet.action@v2.1.1
107+
with:
108+
spreadsheetId: ${{secrets.SPREADSHEET_ID}}
109+
commands: | # list of commands, specified as a valid JSON string
110+
[
111+
{ "command": "getData", "args": { "worksheetTitle": "Sheet1", "minCol": 1, "maxCol": 30 } }
112+
]
113+
env:
114+
GSHEET_CLIENT_EMAIL: ${{ secrets.SERVICE_EMAIL }}
115+
GSHEET_PRIVATE_KEY: ${{ secrets.SERVICE_KEY }}
116+
- id: step1
117+
name: dump results
118+
env:
119+
# the output of the action can be found in ${{ steps.update_worksheet.outputs.results }}
120+
RESULTS: ${{ steps.get_worksheet.outputs.results }}
121+
run: |
122+
# the result command will be stored in environment variable $id
123+
cmd=$(echo "${RESULTS}" | jq ".results[0].result.rawData")
124+
# echo "cmd = $cmd \n"
125+
# echo "RESULTS = ${RESULTS} \n"
126+
branch=${{ env.base }}
127+
assignment=${{ env.assignment }}
128+
gitid="\"${{ env.login }}\""
129+
lastrow=0
130+
for i in {1..100}
131+
do
132+
t=$(echo "${cmd}" | jq ".[$i][0]")
133+
# echo "$t"
134+
# echo "$gitid"
135+
if [ "$t" = "$gitid" ]; then
136+
echo "FOUND: t=$t gitid=$gitid i=$i"
137+
current_result=$(echo "${cmd}" | jq ".[$i][$((assignment*2))]")
138+
echo "current_result=$current_result"
139+
if [ -n "$current_result" ] && [ "$current_result" != "\"\"" ] && [ "$current_result" != "\"0.01\"" ]; then
140+
echo "Current result in the GSHEET current_result=$current_result"
141+
echo "There is not need for update; aborting"
142+
echo "update_is_needed=false" >> $GITHUB_OUTPUT
143+
exit 0
144+
fi
145+
j="[{ \"command\": \"updateData\", \"args\": {\"worksheetTitle\": \"Sheet1\", \"data\": [["\"$result\"", "\"$result\""]], \"minCol\": $((assignment*2)), \"minRow\": $((i+1)) }} ]"
146+
echo "update command: $j \n"
147+
echo "id=$j" >> $GITHUB_OUTPUT
148+
break
149+
else
150+
echo "Strings are not equal: t=$t gitid=$gitid"
151+
if [ -z $t ] || [ -z "$t" ] || [ $t = null ] || [ $t = "" ] || [ $t = "\"\"" ] || [ "$t" = "\"\"" ] || [ "$t" = "" ]; then
152+
echo "t=$t is null; I.e. $gitid is not found in the sheet"
153+
break
154+
fi
155+
lastrow=$i
156+
echo "lastrow -> $lastrow"
157+
fi
158+
done
159+
# if the gitid is not found in the sheet
160+
# then write in var j command that adds the gitid to the sheet
161+
if [[ ! -n "$j" ]]
162+
then
163+
j="[{ \"command\": \"updateData\", \"args\": {\"worksheetTitle\": \"Sheet1\", \"data\": [[ "$gitid" ]], \"minCol\": 1, \"minRow\": $((lastrow+2)) }}, { \"command\": \"updateData\", \"args\": {\"worksheetTitle\": \"Sheet1\", \"data\": [["\"$result\"", "\"$result\""]], \"minCol\": $((assignment*2)), \"minRow\": $((lastrow+2)) }} ]"
164+
echo "update command: $j \n"
165+
echo "id=$j" >> $GITHUB_OUTPUT
166+
fi
167+
echo "update_is_needed=true" >> $GITHUB_OUTPUT
168+
169+
job3:
170+
runs-on: ubuntu-latest
171+
needs: [job2]
172+
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' && needs.job2.outputs.update_is_needed == 'true' }}
173+
steps:
174+
- id: 'update_worksheet'
175+
uses: jroehl/gsheet.action@v2.1.1
176+
with:
177+
spreadsheetId: ${{secrets.SPREADSHEET_ID}}
178+
commands: ${{needs.job2.outputs.output_id_number}}
179+
env:
180+
GSHEET_CLIENT_EMAIL: ${{ secrets.SERVICE_EMAIL }}
181+
GSHEET_PRIVATE_KEY: ${{ secrets.SERVICE_KEY }}

0 commit comments

Comments
 (0)