build json files and md-cache #927
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: build json files and md-cache | |
on: | |
schedule: # every day at 2am and 2pm | |
- cron: '0 2,14 * * *' | |
workflow_dispatch: | |
repository_dispatch: | |
types: [update-website] | |
jobs: | |
build-component-json: | |
runs-on: ubuntu-latest | |
environment: static-file-build | |
if: (github.event_name == 'schedule' && github.repository == 'nf-core/website') || (github.event_name != 'schedule') | |
steps: | |
# Set up the main website repo | |
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 | |
with: | |
fetch-depth: 0 # Don't do a shallow clone | |
token: ${{secrets.NF_CORE_BOT_AUTH_TOKEN}} # Needed for pushing back to the repo | |
# install npm dependencies | |
- name: Set up node.js | |
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4 | |
with: | |
node-version: 20 | |
cache: 'npm' | |
- name: Install dependencies | |
run: npm ci | |
- name: create pipeline.json | |
run: npm run build-pipeline-json | |
env: | |
GITHUB_TOKEN: ${{ secrets.PIPLINE_JSON_BUILD_TOKEN }} | |
- name: create component.json | |
run: npm run build-component-json | |
env: | |
GITHUB_TOKEN: ${{ secrets.PIPLINE_JSON_BUILD_TOKEN }} | |
- name: make md cache | |
run: npm run build-md-cache | |
env: | |
GITHUB_TOKEN: ${{ secrets.CREATE_CACHE_MD_TOKEN }} | |
# check lines if too many lines of code have been changed in /public/pipelines.json and /pulic/components.json | |
# also check if .cache.tar.xz is smaller than before (shouldn't happen) | |
- name: check lines | |
run: | | |
diff_output=$(git diff --shortstat public/pipelines.json public/components.json) | |
lines_added=$(echo $diff_output | awk '{print $4}') | |
lines_removed=$(echo $diff_output | awk '{print $6}') | |
changes=$((lines_added - lines_removed)) | |
if (($changes < -100)) || (($changes > 100)); then | |
file_size_before=$(echo $diff_output | awk '{print $4}') | |
file_size_after=$(echo $diff_output | awk '{print $6}') | |
changes=true | |
fi | |
if [ ! $changes ]; then | |
diff_output=$(git diff --stat .cache.tar.xz) | |
file_size_before=$(echo $diff_output | awk '{print $4}') | |
file_size_after=$(echo $diff_output | awk '{print $6}') | |
changes_tmp=$((file_size_before - file_size_after)) | |
if ((changes_tmp > 0)); then | |
changes=true | |
else | |
changes=false | |
fi | |
fi | |
echo "changes=$changes" >> "$GITHUB_OUTPUT" | |
# Commit and push the changes if there are not too many lines changed | |
- name: Commit and push changes | |
if: ${{ !steps.check_lines.outputs.changes }} | |
run: | | |
git config user.email "[email protected]" | |
git config user.name "nf-core-bot" | |
git config push.default upstream | |
git status | |
git diff --quiet || (git commit -am "[automated] Update json files and markdown cache" && git push) | |
# Create a PR if there are too many lines changed | |
- name: Create PR with changes | |
if: ${{ steps.check_lines.outputs.changes }} | |
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7 | |
with: | |
token: ${{ secrets.CREATE_PR_TOKEN }} | |
commit-message: 'chore: update pipeline.json and component.json' | |
title: 'chore: update pipeline.json and component.json' | |
body: 'This PR was automatically created by a GitHub Action because there were too many lines changed in the pipeline.json and component.json files.' | |
branch: 'chore/update-pipeline-json-and-component-json' | |
delete-branch: true | |
draft: false |