forked from eclipse-tractusx/sldt-semantic-models
-
Notifications
You must be signed in to change notification settings - Fork 0
133 lines (126 loc) · 4.42 KB
/
upload.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
#
# Copyright (c) 2021 T-Systems International GmbH (Catena-X Consortium)
# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH
#
# See the AUTHORS file(s) distributed with this work for additional
# information regarding authorship.
#
# See the LICENSE file(s) distributed with this work for
# additional information regarding license terms.
#
name: 1 Upload
on:
workflow_run:
workflows: ["0 Governance"]
types:
- completed
jobs:
upload-models:
name: 00 Upload Models
runs-on: ubuntu-latest
permissions:
contents: read
actions: read
steps:
- name: set environment variables
run: |
echo "WORKSPACE_UPPERCASE=INT" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v3
- name: Download artifact
uses: actions/[email protected]
with:
script: |
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 == "output"
})[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}}/output.zip', Buffer.from(download.data));
- run: |
unzip output.zip
cat output.json
- name: Fetch Access Token
id: token_request
env:
CLIENT_ID: ${{ secrets[format('CLIENT_ID_{0}', env.WORKSPACE_UPPERCASE)] }}
CLIENT_SECRET: ${{ secrets[format('CLIENT_SECRET_{0}', env.WORKSPACE_UPPERCASE)] }}
IDP_URL: ${{ secrets[format('IDP_URL_{0}', env.WORKSPACE_UPPERCASE)] }}
run: |
response=$(curl --request POST \
--url "https://$IDP_URL" \
--header 'content-type: application/x-www-form-urlencoded' \
--data-urlencode grant_type=client_credentials \
--data-urlencode client_id=$CLIENT_ID \
--data-urlencode client_secret=$CLIENT_SECRET )
access_token=$( echo $response | jq -r '.access_token' )
if [ $access_token == null ]
then
echo "Error: Got empty token"
exit 1
fi
echo "ACCESS_TOKEN=$access_token" >> $GITHUB_ENV
- name: Upload
uses: ./.github/actions/upload
with:
SEMANTIC_HUB_URL: ${{ secrets[format('SEMANTIC_HUB_{0}_BASE', env.WORKSPACE_UPPERCASE)] }}
TOKEN: ${{ env.ACCESS_TOKEN }}
add-comments:
name: 01 Add comments
runs-on: ubuntu-latest
permissions:
contents: read
actions: read
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download artifact
uses: actions/[email protected]
with:
script: |
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 == "validation-output"
})[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}}/validation-output.zip', Buffer.from(download.data));
- name: Unzip
run: |
unzip validation-output.zip
cat validation-output.json
- name: Upload comments
uses: actions/[email protected]
with:
script: |
var fs = require('fs');
var rawOutputValidationFile = fs.readFileSync('validation-output.json');
var validationOutput = JSON.parse(rawOutputValidationFile);
validationOutput.comments.forEach((comment) => {
github.rest.issues.createComment({
issue_number: validationOutput.prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
})
})