diff --git a/.github/workflows/3a_approved_pull_request.yml b/.github/workflows/3a_approved_pull_request.yml index 7c01733e..1290e46a 100644 --- a/.github/workflows/3a_approved_pull_request.yml +++ b/.github/workflows/3a_approved_pull_request.yml @@ -36,22 +36,37 @@ jobs: id: get_wpid working-directory: sandbox-wp.gh.io run: | - WPID=$(ls _pathways/ | grep -E '^WP[0-9]+\.md$' | sort -V | tail -n 1) - WPID=$(echo $WPID | sed 's/\.md//') - WPID_NUM=$(echo $WPID | sed 's/WP//') - WPID_NUM=$((WPID_NUM + 1)) - WPID="WP$WPID_NUM" + PR_NUMBER=${{ github.event.inputs.pr_number }} + DRAFT_FILE=$(find _drafts -name "WP*__PR${PR_NUMBER}.md" | head -n 1) + + if [ -n "$DRAFT_FILE" ]; then + WPID_NUM=$(echo $DRAFT_FILE | sed -E 's/WP([0-9]+)__PR.*/\1/') + if [ "$WPID_NUM" -eq "0" ]; then + WPID=$(ls _pathways/ | grep -E '^WP[0-9]+\.md$' | sort -V | tail -n 1) + WPID=$(echo $WPID | sed 's/\.md//') + WPID_NEW=$(echo $WPID | sed 's/WP//') + WPID_NEW=$((WPID_NEW + 1)) + else + WPID_NEW=$((WPID_NUM)) + fi + else + echo "No draft file found for PR #${PR_NUMBER}" + exit 1 + fi + + WPID="WP${WPID_NEW}" echo "::set-output name=wpid::$WPID" + echo "::set-output name=old_prefix::WP${WPID_NUM}__PR${PR_NUMBER}" - name: Rename and Move Files working-directory: sandbox-wp.gh.io run: | - PR_NUMBER=${{ github.event.inputs.pr_number }} + OLD_PREFIX=${{ steps.get_wpid.outputs.old_prefix }} WPID=${{ steps.get_wpid.outputs.wpid }} # Process .md files - find _drafts -type f -name "WP0__PR${PR_NUMBER}.md" | while read file; do - new_file=$(echo $file | sed "s/WP0__PR${PR_NUMBER}/${WPID}/") + find _drafts -type f -name "${OLD_PREFIX}.md" | while read file; do + new_file=$(echo $file | sed "s/${OLD_PREFIX}/${WPID}/") new_file=$(basename $new_file) mkdir -p "../sandbox-wp-db/pathways/${WPID}" cp "$file" "../sandbox-wp-db/pathways/${WPID}/${new_file}" @@ -59,15 +74,15 @@ jobs: done # Process .tsv files - find _data/drafts -type f -name "WP0__PR${PR_NUMBER}*.tsv" | while read file; do - new_file=$(echo $file | sed "s/WP0__PR${PR_NUMBER}/${WPID}/") + find _data/drafts -type f -name "${OLD_PREFIX}*.tsv" | while read file; do + new_file=$(echo $file | sed "s/${OLD_PREFIX}/${WPID}/") new_file=$(basename $new_file) mv "$file" "_data/${new_file}" done # Process files in draft_assets - find draft_assets -type f -name "WP0__PR${PR_NUMBER}*" | while read file; do - new_file=$(echo $file | sed "s/WP0__PR${PR_NUMBER}/${WPID}/") + find draft_assets -type f -name "${OLD_PREFIX}*" | while read file; do + new_file=$(echo $file | sed "s/${OLD_PREFIX}/${WPID}/") new_file=$(basename $new_file) #Skip SVG files if [[ $file != *.svg ]]; then diff --git a/.github/workflows/3b_rejected_pull_request.yml b/.github/workflows/3b_rejected_pull_request.yml index d3f2d959..d1b1b9d2 100644 --- a/.github/workflows/3b_rejected_pull_request.yml +++ b/.github/workflows/3b_rejected_pull_request.yml @@ -19,10 +19,9 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} PR_NUMBER: ${{ github.event.inputs.pr_number }} run: | - # Remove draft files from sandbox-wp.gh.io gh repo clone wikipathways/sandbox-wp.gh.io cd sandbox-wp.gh.io - find _drafts _data/drafts draft_assets -type f -name "WP0__PR${PR_NUMBER}*" -delete + find _drafts _data/drafts draft_assets -type f -name "WP*__PR${PR_NUMBER}*" -delete git config user.name github-actions git config user.email github-actions@github.com git add .