1 Upload #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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 | |
}) | |
}) |