Skip to content

Commit

Permalink
closes #25
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderPico committed Sep 20, 2024
1 parent 9ec2676 commit cbb7dae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
39 changes: 27 additions & 12 deletions .github/workflows/3a_approved_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,38 +36,53 @@ 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}"
mv "$file" "_pathways/${new_file}"
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
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/3b_rejected_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]
git add .
Expand Down

0 comments on commit cbb7dae

Please sign in to comment.