Skip to content

refactor metadata suggestion diff auto-commment on PR #81

refactor metadata suggestion diff auto-commment on PR

refactor metadata suggestion diff auto-commment on PR #81

name: AutocompleteMetadata
on:
pull_request_target:
paths:
- 'Molecules/membrane/**/metadata.yaml'
- 'Molecules/solution/**/metadata.yaml'
permissions:
contents: read
pull-requests: write
jobs:
add-metadata:
runs-on: ubuntu-latest
steps:
- name: Checkout BilayerData
uses: actions/checkout@v6
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
persist-credentials: false
- name: Clone Databank and install
run: |
git clone --depth 1 https://github.com/NMRlipids/FAIRMD_lipids.git "$RUNNER_TEMP/Databank"
pip install "$RUNNER_TEMP/Databank"
- name: Install the gh cli
uses: ksivamuthu/actions-setup-gh-cli@v3
with:
version: 2.83.0
- name: Find changed metadata.yaml files
id: files
env:
GH_TOKEN: ${{ github.token }}
run: |
changed_files=$(gh api --paginate \
"repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" \
--jq '.[] | select(.status != "removed") | .filename' \
| grep -E '^Molecules/(membrane|solution)/[^/]+/metadata\.yaml$' || true)
{
echo "changed_files<<EOF"
echo "$changed_files"
echo "EOF"
} >> "$GITHUB_OUTPUT"
echo "Changed files:"
echo "$changed_files"
- name: Run AddMetadata.py and create suggestions
if: steps.files.outputs.changed_files != ''
env:
CHANGED_FILES: ${{ steps.files.outputs.changed_files }}
run: |
printf '%s\n' "$CHANGED_FILES" | while IFS= read -r f; do
[ -n "$f" ] && python "$RUNNER_TEMP/Databank/developer/autocomplete_metadata.py" "$f"
done
- name: Suggest changes on PR
if: steps.files.outputs.changed_files != ''
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
diff=$(git diff)
if [ -n "$diff" ]; then
gh pr comment ${{ github.event.pull_request.number }} \
--repo ${{ github.repository }} \
--body "**Metadata autocomplete suggestions:**
\`\`\`diff
$diff
\`\`\`"
fi

Check failure on line 73 in .github/workflows/AutocompleteMetadata.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/AutocompleteMetadata.yml

Invalid workflow file

You have an error in your yaml syntax on line 73