requirements #5
Workflow file for this run
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
name: Generate Model Card | |
on: | |
pull_request | |
permissions: | |
pull-requests: write | |
contents: write | |
jobs: | |
modelcard_generator: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Get commit messages | |
run: | | |
git fetch origin ${{ github.base_ref }}:${{ github.base_ref }} | |
git fetch origin ${{ github.head_ref }}:${{ github.head_ref }} | |
HEAD_BRANCH=${{ github.head_ref }} | |
BASE_BRANCH=${{ github.base_ref }} | |
COMMIT_MESSAGES=$(git log origin/${BASE_BRANCH}..origin/${HEAD_BRANCH} --pretty=format:"%s" | head -n 1) | |
if echo "$COMMIT_MESSAGES" | grep -q "modelcards"; then | |
echo "exists=true" >> $GITHUB_ENV | |
else | |
echo "exists=false" >> $GITHUB_ENV | |
fi | |
- name: Set up Python | |
if: env.exists == 'true' | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.12.7' | |
- name: Install dependencies | |
if: env.exists == 'true' | |
run: | | |
pip install mlflow==2.16.2 | |
pip install jinja2 | |
sudo apt-get update | |
sudo apt-get install -y jq | |
- name: Create Model Cards | |
if: env.exists == 'true' | |
run: | | |
OUTPUT=$(python docs/src/main.py) | |
if [ -n "$OUTPUT" ]; then | |
COMMENT=$(echo "$OUTPUT" | jq -Rs .) | |
PR_NUMBER=${{ github.event.pull_request.number }} | |
PR_NUMBER=${{ github.event.pull_request.number }} | |
curl -X POST \ | |
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/${{ github.repository }}/issues/$PR_NUMBER/comments \ | |
-d "{\"body\":$COMMENT}" | |
fi | |
- name: Commit and push Model Cards | |
if: env.exists == 'true' | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add docs/modelcards/ | |
git commit -m "Model Cards generated" || echo "Nothing to commit" | |
git pull --rebase origin ${{ github.head_ref }} | |
git push origin HEAD:${{ github.head_ref }} |