-
Notifications
You must be signed in to change notification settings - Fork 4
167 lines (164 loc) · 9.05 KB
/
hackathon_qavalidator.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
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
name: hackathon_qavalidator_award
on:
push:
paths:
- 'static/admin/userdata/hackathons/badges/qavalidator/awards/**.yml'
jobs:
job_verify_membership:
name: verify_membership
runs-on: ubuntu-latest
outputs:
output1: ${{ steps.ismember.outputs.ismember }}
steps:
- name: review event details
run: |
env
cat /home/runner/work/_temp/_github_workflow/event.json
- name: set source repo as org_repo
run: |
echo $(echo org_repo="$GITHUB_REPOSITORY") >> $GITHUB_ENV
- name: install yq
run: |
sudo wget https://github.com/mikefarah/yq/releases/download/v4.6.0/yq_linux_amd64 -O /usr/bin/yq &&\
sudo chmod +x /usr/bin/yq
- name: pull member record file
run: |
echo ${{ github.event.commits[0].author.username }}
curl -H "Authorization: token ${{ secrets.NINJABOTGURU }}" \
"https://raw.githubusercontent.com/modernappsninjas/${{ github.event.commits[0].author.username }}/main/static/userdata/member_record.yml" \
-o /tmp/member_record.yml
cat /tmp/member_record.yml
- name: check if member record already exists to determine if this is a duplicate request
run: |
authorGitubId=$(yq e '.memberGithubId' /tmp/member_record.yml)
if [ $(echo "${authorGithubId}") == "null" ]
then
echo ismember=false >> $GITHUB_ENV
echo "the requesting user is not a member"
else
echo ismember=true >> $GITHUB_ENV
echo "the requesting user is a member"
fi
- id: ismember
if: env.ismember == 'true'
run: echo "::set-output name=ismember::true"
# There is currently no method to notify a user if they are not a member, so for the time being administrators should check membership before approving, and this check will only be used as a backup measure, and in the event that a nonmember attempts to run this workflow it will fail with no notification provided and therefore dependent on the requesting user to request assistance
# In the future, one potential method we could implement to notify a nonmember user would be to open an issue ticket on the source repository on which they opened a pullrequest, at-mention them with instructions, and immediately close the issue ticket so they can still find it through their notifications but there is no further maintenance requirement for administrators
job_award_badge:
# call badgr and provision badge ()
name: job_award
needs: job_verify_membership
runs-on: ubuntu-latest
if: needs.job_verify_membership.outputs.output1 == 'true'
steps:
- name: review event details
run: |
env
cat /home/runner/work/_temp/_github_workflow/event.json
- name: install yq
run: |
sudo wget https://github.com/mikefarah/yq/releases/download/v4.6.0/yq_linux_amd64 -O /usr/bin/yq &&\
sudo chmod +x /usr/bin/yq
- name: set org/repo as org_repo
run: |
echo $(echo org_repo="$GITHUB_REPOSITORY") >> $GITHUB_ENV
org_repo="$GITHUB_REPOSITORY"
echo $org_repo
- name: pull member record file
run: |
curl -H "Authorization: token ${{ secrets.NINJABOTGURU }}" \
"https://raw.githubusercontent.com/modernappsninjas/${{ github.event.commits[0].author.username }}/main/static/userdata/member_record.yml" \
-o /tmp/member_record.yml
cat /tmp/member_record.yml
- name: make assertion to award digital badge to recipient
run: |
preferredemailaddress=$(yq e '.preferredEmailAddress' /tmp/member_record.yml)
badgeclass_entity_id=0UXs-GWSTMSUA7D3lOC_Ug
reponame=${{ github.event.repository.name }}
lorepo=$(echo ${reponame,,})
echo "lorepo is: ${lorepo}"
badgrtoken=$(curl -X POST "https://api.badgr.io/o/token" -d "username=${{ secrets.BADGREMAIL }}&password=${{ secrets.BADGRPASSWORD }}" | jq -r '.access_token')
echo "badgrtoken is: ${badgrtoken}"
curl -X POST \
"https://api.badgr.io/v2/badgeclasses/${badgeclass_entity_id}/assertions" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer ${badgrtoken}" \
--data-raw '{
"recipient": {
"identity": "'$(echo ${preferredemailaddress})'",
"type": "email",
"hashed": true
},
"evidence": [
{
"url": "https://modernappsninjas.github.io/${{ github.event.commits[0].author.username }}/"
}
],
"notify": true
}' >> /tmp/assert_call_response.json
cat /tmp/assert_call_response.json
- name: review variables from assertion response
run: |
echo "status.success is : $(jq -r '.status.success' /tmp/assert_call_response.json)"
jq -r '.status.success' /tmp/assert_call_response.json > /tmp/assert_success
echo "result.entityId is : $(jq -r '.result[0].entityId' /tmp/assert_call_response.json)"
jq -r '.result[0].entityId' /tmp/assert_call_response.json > /tmp/badge_entityId
echo "result.openBadgeId is : $(jq -r '.result[0].openBadgeId' /tmp/assert_call_response.json)"
jq -r '.result[0].openBadgeId' /tmp/assert_call_response.json > /tmp/badge_openBadgeId
- name: pull badge meta file
run: |
curl -H "Authorization: token ${{ secrets.NINJABOTGURU }}" \
"https://raw.githubusercontent.com/${{ env.org_repo }}/main/static/admin/assets/hackathons/badges/qavalidator/cards/badge_meta.yml" \
-o /tmp/badge_meta.yml
cat /tmp/badge_meta.yml
- name: pull badge data stub
run: |
curl -H "Authorization: token ${{ secrets.NINJABOTGURU }}" \
"https://raw.githubusercontent.com/${{ env.org_repo }}/main/static/admin/assets/hackathons/badges/qavalidator/cards/member_badge_card_stub.md" \
-o /tmp/member_badge_card_stub.md
cat /tmp/member_badge_card_stub.md
- name: prepare hackathon badge card
run: |
# combine badge meta, member badge card stub, member github ids and openbadge ids to create new member hackathon badge card file
cat /tmp/badge_meta.yml > /tmp/member_badge_card.md
cat /tmp/member_badge_card_stub.md >> /tmp/member_badge_card.md
echo " " >> /tmp/member_badge_card.md
echo "Member_Github_Account_Login: ${{ github.event.commits[0].author.username }} " >> /tmp/member_badge_card.md
echo " " >> /tmp/member_badge_card.md
echo "OpenBadge_EntityId: $(cat /tmp/badge_entityId)" >> /tmp/member_badge_card.md
echo " " >> /tmp/member_badge_card.md
echo 'OpenBadge_Url: ['$(cat /tmp/badge_openBadgeId)']('$(cat /tmp/badge_openBadgeId)')' >> /tmp/member_badge_card.md
echo " " >> /tmp/member_badge_card.md
cat /tmp/member_badge_card.md
cat /tmp/member_badge_card.md | base64 -w 0 > /tmp/member_badge_card.md.base64
- name: post member badge card to member repo certs dir
run: |
curl -X PUT \
-H "Authorization: token ${{ secrets.NINJABOTGURU }}" \
-H "Accept: application/vnd.github.v3+json" \
-d '{"message": "Posting updated member badge record card", "content": "'$(cat /tmp/member_badge_card.md.base64)'"}' \
"https://api.github.com/repos/modernappsninjas/${{ github.event.commits[0].author.username }}/contents/content/english/certs/${{ github.event.repository.name }}_qavalidator.md" \
-o /tmp/member_badge_card_post_response.json
- name: gather ID and slug for modernappsninja members team
run: |
curl -s \
-H "Authorization: token ${{ secrets.NINJABOTGURU }}" \
"https://api.github.com/orgs/modernappsninja/teams" \
-o /tmp/ninja_teams_list.json
# gather members team id
cat /tmp/ninja_teams_list.json | jq -r 'map(select(.name=="'Members'")) | .[].id' > /tmp/members_team_id
cat /tmp/members_team_id
echo members_team_id=$(cat /tmp/members_team_id) >> $GITHUB_ENV
# gather members team slug
cat /tmp/ninja_teams_list.json | jq -r 'map(select(.name=="'Members'")) | .[].slug' > /tmp/members_team_slug
cat /tmp/members_team_slug
echo members_team_slug=$(cat /tmp/members_team_slug) >> $GITHUB_ENV
- name: update members discussion board hackathon award thread about new badge award
run: |
curl -X POST \
-H "Authorization: token ${{ secrets.NINJABOTGURU }}" \
-H "Accept: application/vnd.github.v3+json" \
-d '{"body":"Congratulations to @'${{ github.event.commits[0].author.username }}' for earning the Hackathon QA Validator Badge! Thank you for contributing to the community!"}' \
"https://api.github.com/orgs/modernappsninja/teams/${{ env.members_team_slug }}/discussions/9/comments" \
-o /tmp/add_course_team_discussion_response.json
cat /tmp/add_course_team_discussion_response.json