Copy Parse Markdown and Generate JSON from Source Repo #37
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: Copy Parse Markdown and Generate JSON from Source Repo | |
on: | |
workflow_dispatch: | |
inputs: | |
source_repo: | |
description: 'Source repository name' | |
required: false | |
default: 'DmitryRyumin/NewEraAI-Papers' | |
source_file_path: | |
description: 'Path to the file in the source repository' | |
required: false | |
default: 'code/markdown_to_json_parser.py' | |
code_directory: | |
description: 'Directory where code is stored' | |
required: false | |
default: 'code' | |
display_file_contents: | |
description: 'Whether or not to display the contents of the doanload file and the destination file' | |
required: false | |
default: 'false' | |
schedule: | |
- cron: '30 23 * * *' | |
jobs: | |
copy-code: | |
runs-on: ubuntu-latest | |
env: | |
SOURCE_FILE_PATH: ${{ github.workspace }}/${{ github.event.inputs.code_directory }}/markdown_to_json_parser_new.py | |
SOURCE_DESTINATION_FILE_PATH: ${{ github.workspace }}/${{ github.event.inputs.source_file_path }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Download source file | |
run: | | |
if mkdir -p "${{ github.workspace }}/${{ github.event.inputs.code_directory }}"; then | |
echo "Directory created successfully or already existed." | |
else | |
echo "Failed to create directory." | |
exit 1 | |
fi | |
source_url="https://raw.githubusercontent.com/${{ github.event.inputs.source_repo }}/main/${{ github.event.inputs.source_file_path }}" | |
curl -o "${{ env.SOURCE_FILE_PATH }}" "$source_url" | |
echo "File downloaded successfully" | |
- name: Display content of the downloaded source file | |
run: | | |
if [ -f "${{ env.SOURCE_FILE_PATH }}" ]; then | |
if [ "${{ github.event.inputs.display_file_contents }}" == 'true' ]; then | |
cat "${{ env.SOURCE_FILE_PATH }}" | |
else | |
echo "Displaying content is blocked." | |
fi | |
else | |
echo "Source file does not exist." | |
exit 1 | |
fi | |
- name: Display content of destination file from target repository | |
run: | | |
if [ -f "${{ env.SOURCE_DESTINATION_FILE_PATH }}" ]; then | |
if [ "${{ github.event.inputs.display_file_contents }}" == 'true' ]; then | |
cat "${{ env.SOURCE_DESTINATION_FILE_PATH }}" | |
else | |
echo "Displaying content is blocked." | |
fi | |
else | |
echo "Source file does not exist." | |
fi | |
- name: Compare and handle files | |
run: | | |
if [ -f "${{ env.SOURCE_DESTINATION_FILE_PATH }}" ]; then | |
if cmp -s "${{ env.SOURCE_DESTINATION_FILE_PATH }}" "${{ env.SOURCE_FILE_PATH }}"; then | |
echo "Files are equal. Deleting SOURCE_FILE_PATH." | |
rm "${{ env.SOURCE_FILE_PATH }}" | |
else | |
echo "Files are not equal. Replacing SOURCE_DESTINATION_FILE_PATH with content from SOURCE_FILE_PATH." | |
cat "${{ env.SOURCE_FILE_PATH }}" > "${{ env.SOURCE_DESTINATION_FILE_PATH }}" | |
rm "${{ env.SOURCE_FILE_PATH }}" | |
fi | |
else | |
echo "SOURCE_DESTINATION_FILE_PATH does not exist. Renaming SOURCE_FILE_PATH to SOURCE_DESTINATION_FILE_PATH." | |
if [ -f "${{ env.SOURCE_FILE_PATH }}" ] && [ -f "${{ env.SOURCE_DESTINATION_FILE_PATH }}" ]; then | |
mv "${{ env.SOURCE_FILE_PATH }}" "${{ env.SOURCE_DESTINATION_FILE_PATH }}" | |
else | |
echo "One or both of the files do not exist." | |
fi | |
fi | |
- name: Display working code directory content | |
run: | | |
ls -al "${{ github.workspace }}/${{ github.event.inputs.code_directory }}" | |
- name: Auto commit changes | |
uses: stefanzweifel/git-auto-commit-action@v5 | |
with: | |
commit_message: 'Copy Parse Markdown and Generate JSON from Source Repo' | |
env: | |
PAPER_TOKEN: ${{ secrets.PAPER_TOKEN }} | |
- name: Set output status | |
run: echo "status=${{ steps.parse.outcome }}" >> $GITHUB_ENV |