-
Notifications
You must be signed in to change notification settings - Fork 272
181 lines (175 loc) · 7.39 KB
/
postaction.yml
File metadata and controls
181 lines (175 loc) · 7.39 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
name: PostAction
on:
workflow_run:
workflows: ["CheckPullRequest"]
types:
- completed
jobs:
job2:
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
outputs:
output_id_number: ${{ steps.step1.outputs.id }}
update_is_needed: ${{ steps.step1.outputs.update_is_needed }}
steps:
- name: 'Download artifact'
uses: actions/github-script@v6
with:
script: |
console.log(${{ github.event.workflow_run.id }});
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "share_info";
})[0];
var download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{ github.workspace }}/share_info.zip', Buffer.from(download.data));
- run: unzip share_info.zip
- run: |
echo "university=$(cat university.txt)" >> $GITHUB_ENV
echo "assignment=$(cat assignment_number.txt)" >> $GITHUB_ENV
echo "login=$(cat gitid.txt)" >> $GITHUB_ENV
echo "base=$(cat base.txt)" >> $GITHUB_ENV
- id: 'get_deadlines_worksheet'
uses: jroehl/gsheet.action@v2.1.1
with:
spreadsheetId: ${{secrets.SPREADSHEET_ID}}
commands: | # list of commands, specified as a valid JSON string
[
{ "command": "getData", "args": { "worksheetTitle": "Deadlines", "minCol": 1, "maxCol": 20 } }
]
env:
GSHEET_CLIENT_EMAIL: ${{ secrets.SERVICE_EMAIL }}
GSHEET_PRIVATE_KEY: ${{ secrets.SERVICE_KEY }}
- id: check-deadline
name: check-deadline
env:
RESULTS: ${{ steps.get_deadlines_worksheet.outputs.results }}
run: |
cmd=$(echo "${RESULTS}" | jq ".results[0].result.rawData")
assignment=${{ env.assignment }}
university="\"${{ env.university }}\""
# Find Deadline in the Google Sheet
row=0
for j in {1..10}
do
t=$(echo "${cmd}" | jq ".[$j][0]")
if [ $t = $university ]; then
echo "university FOUND: $j"
row=$j
echo $row
break
fi
done
if [ $row -eq 0 ]; then
echo "ERROR: Deadline for $university not found!"
exit 1
fi
deadline=$(echo "${cmd}" | jq ".[$row][${assignment}]")
echo "Deadline for $university for assignment number $assignment is $deadline"
# Get submission time
submission_time="\"${{ github.event.workflow_run.head_commit.timestamp }}\""
# Check Deadline
echo $submission_time
echo $deadline
if [[ $submission_time > $deadline ]]; then
echo "result=0.01" >> $GITHUB_ENV
echo "FIASCO: The deadline has expired"
else
echo "result=1" >> $GITHUB_ENV
echo "OK: you are on time!"
fi
# - name: Check out code
# uses: actions/checkout@v2
# - name: Comment PR
# uses: thollander/actions-comment-pull-request@v2
# with:
# message: |
# All checks have successfully passed!
# The assignment is submitted on time.
# reactions: rocket
- id: 'get_worksheet'
uses: jroehl/gsheet.action@v2.1.1
with:
spreadsheetId: ${{secrets.SPREADSHEET_ID}}
commands: | # list of commands, specified as a valid JSON string
[
{ "command": "getData", "args": { "worksheetTitle": "Sheet1", "minCol": 1, "maxCol": 30 } }
]
env:
GSHEET_CLIENT_EMAIL: ${{ secrets.SERVICE_EMAIL }}
GSHEET_PRIVATE_KEY: ${{ secrets.SERVICE_KEY }}
- id: step1
name: dump results
env:
# the output of the action can be found in ${{ steps.update_worksheet.outputs.results }}
RESULTS: ${{ steps.get_worksheet.outputs.results }}
run: |
# the result command will be stored in environment variable $id
cmd=$(echo "${RESULTS}" | jq ".results[0].result.rawData")
# echo "cmd = $cmd \n"
# echo "RESULTS = ${RESULTS} \n"
branch=${{ env.base }}
assignment=${{ env.assignment }}
gitid="\"${{ env.login }}\""
lastrow=0
for i in {1..100}
do
t=$(echo "${cmd}" | jq ".[$i][0]")
# echo "$t"
# echo "$gitid"
if [ "$t" = "$gitid" ]; then
echo "FOUND: t=$t gitid=$gitid i=$i"
current_result=$(echo "${cmd}" | jq ".[$i][$((assignment*2))]")
echo "current_result=$current_result"
if [ -n "$current_result" ] && [ "$current_result" != "\"\"" ] && [ "$current_result" != "\"0.01\"" ]; then
echo "Current result in the GSHEET current_result=$current_result"
echo "There is not need for update; aborting"
echo "update_is_needed=false" >> $GITHUB_OUTPUT
exit 0
fi
j="[{ \"command\": \"updateData\", \"args\": {\"worksheetTitle\": \"Sheet1\", \"data\": [["\"$result\"", "\"$result\""]], \"minCol\": $((assignment*2)), \"minRow\": $((i+1)) }} ]"
echo "update command: $j \n"
echo "id=$j" >> $GITHUB_OUTPUT
break
else
echo "Strings are not equal: t=$t gitid=$gitid"
if [ -z $t ] || [ -z "$t" ] || [ $t = null ] || [ $t = "" ] || [ $t = "\"\"" ] || [ "$t" = "\"\"" ] || [ "$t" = "" ]; then
echo "t=$t is null; I.e. $gitid is not found in the sheet"
break
fi
lastrow=$i
echo "lastrow -> $lastrow"
fi
done
# if the gitid is not found in the sheet
# then write in var j command that adds the gitid to the sheet
if [[ ! -n "$j" ]]
then
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)) }} ]"
echo "update command: $j \n"
echo "id=$j" >> $GITHUB_OUTPUT
fi
echo "update_is_needed=true" >> $GITHUB_OUTPUT
job3:
runs-on: ubuntu-latest
needs: [job2]
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' && needs.job2.outputs.update_is_needed == 'true' }}
steps:
- id: 'update_worksheet'
uses: jroehl/gsheet.action@v2.1.1
with:
spreadsheetId: ${{secrets.SPREADSHEET_ID}}
commands: ${{needs.job2.outputs.output_id_number}}
env:
GSHEET_CLIENT_EMAIL: ${{ secrets.SERVICE_EMAIL }}
GSHEET_PRIVATE_KEY: ${{ secrets.SERVICE_KEY }}