|
| 1 | +name: Upload Modified Files to Azure Blob Storage |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + upload_to_azure_after_master_commit: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Fetch files from last merge |
| 13 | + uses: actions/checkout@v4 |
| 14 | + with: |
| 15 | + fetch-depth: 0 |
| 16 | + |
| 17 | + - name: Get all changed markdown files |
| 18 | + id: changed-markdown-files |
| 19 | + uses: tj-actions/changed-files@v41 |
| 20 | + with: |
| 21 | + files: | |
| 22 | + connector/doc/**.md |
| 23 | + include_all_old_new_renamed_files: true |
| 24 | + |
| 25 | + - name: Get all changed images |
| 26 | + id: changed-images |
| 27 | + uses: tj-actions/changed-files@v41 |
| 28 | + with: |
| 29 | + files: | |
| 30 | + connector/images/** |
| 31 | +
|
| 32 | + - name: Summary changed markdown files |
| 33 | + run: | |
| 34 | + echo Docs: |
| 35 | + echo Number of markdown files added: ${{ steps.changed-markdown-files.outputs.added_files_count }} |
| 36 | + echo Number of markdown files modified: ${{ steps.changed-markdown-files.outputs.modified_files_count }} |
| 37 | + echo Number of markdown files renamed: ${{ steps.changed-markdown-files.outputs.renamed_files_count }} |
| 38 | + echo Number of markdown files deleted: ${{ steps.changed-markdown-files.outputs.deleted_files_count }} |
| 39 | + echo Images: |
| 40 | + echo Number of images added: ${{ steps.changed-images.outputs.added_files_count }} |
| 41 | + echo Number of images modified: ${{ steps.changed-images.outputs.modified_files_count }} |
| 42 | + echo Number of images renamed: ${{ steps.changed-images.outputs.renamed_files_count }} |
| 43 | + echo Number of images deleted: ${{ steps.changed-images.outputs.deleted_files_count }} |
| 44 | +
|
| 45 | + - name: Create folder for added, modified and renamed files |
| 46 | + if: steps.changed-markdown-files.outputs.all_changed_and_modified_files_count > 0 || steps.changed-images.outputs.all_changed_and_modified_files_count > 0 |
| 47 | + run: | |
| 48 | + mkdir update_docs |
| 49 | + mkdir update_images |
| 50 | +
|
| 51 | + - name: Add added and modified docs to folders |
| 52 | + if: steps.changed-markdown-files.outputs.added_files_count > 0 || steps.changed-markdown-files.outputs.modified_files_count > 0 |
| 53 | + id: list-docs |
| 54 | + run: | |
| 55 | + for file in ${{ steps.changed-markdown-files.outputs.added_files }}; do |
| 56 | + echo "$file was added" |
| 57 | + cp $file update_docs/ |
| 58 | + done |
| 59 | + for file in ${{ steps.changed-markdown-files.outputs.modified_files }}; do |
| 60 | + echo "$file was modified" |
| 61 | + cp $file update_docs/ |
| 62 | + done |
| 63 | + |
| 64 | + - name: Add added and modified images to folders |
| 65 | + if: steps.changed-images.outputs.added_files_count > 0 || steps.changed-images.outputs.modified_files_count > 0 |
| 66 | + id: list-images |
| 67 | + run: | |
| 68 | + for image in ${{ steps.changed-images.outputs.added_files }}; do |
| 69 | + echo "$image was added" |
| 70 | + cp $image update_images/ |
| 71 | + done |
| 72 | + for image in ${{ steps.changed-images.outputs.modified_files }}; do |
| 73 | + echo "$image was modified" |
| 74 | + cp $image update_images/ |
| 75 | + done |
| 76 | + |
| 77 | + - name: Delete renamed files on azure and add new name to folders |
| 78 | + if: steps.changed-markdown-files.outputs.all_old_new_renamed_files_count > 0 |
| 79 | + uses: azure/CLI@v1 |
| 80 | + with: |
| 81 | + inlineScript: | |
| 82 | + for file in ${{ steps.changed-markdown-files.outputs.all_old_new_renamed_files }}; do |
| 83 | + IFS=',' read -r original renamed <<< "$file" |
| 84 | + if [[ -n $renamed ]]; then |
| 85 | + echo "$original was renamed to $renamed" |
| 86 | + if [[ $original == *doc* ]]; then |
| 87 | + stripped_file="$(basename "$original")" |
| 88 | + cp $renamed update_docs/ |
| 89 | + az storage blob delete -c 'docs' -n $stripped_file --connection-string '${{ secrets.AZUREBLOBSTORAGECS }}' |
| 90 | + fi |
| 91 | + if [[ $original == *images* ]] ; then |
| 92 | + stripped_image="$(basename "$original")" |
| 93 | + cp $renamed update_images/ |
| 94 | + az storage blob delete -c 'images' -n $stripped_image --connection-string '${{ secrets.AZUREBLOBSTORAGECS }}' |
| 95 | + fi |
| 96 | + fi |
| 97 | + done |
| 98 | + |
| 99 | + - name: Delete removed files on azure |
| 100 | + if: steps.changed-markdown-files.outputs.any_deleted == 'true' || steps.changed-images.outputs.any_deleted == 'true' |
| 101 | + uses: azure/CLI@v1 |
| 102 | + with: |
| 103 | + inlineScript: | |
| 104 | + for file in ${{ steps.changed-markdown-files.outputs.deleted_files }}; do |
| 105 | + stripped_file="$(basename "$file")" |
| 106 | + az storage blob delete -c 'docs' -n $stripped_file --connection-string '${{ secrets.AZUREBLOBSTORAGECS }}' |
| 107 | + echo "$file was deleted" |
| 108 | + done |
| 109 | + for image in ${{ steps.changed-images.outputs.deleted_files }}; do |
| 110 | + stripped_image="$(basename "$image")" |
| 111 | + az storage blob delete -c 'images' -n $stripped_image --connection-string '${{ secrets.AZUREBLOBSTORAGECS }}' |
| 112 | + echo "$image was deleted" |
| 113 | + done |
| 114 | + |
| 115 | + - name: Upload docs folder contents to Azure Storage Container |
| 116 | + if: steps.changed-markdown-files.outputs.any_changed == 'true' |
| 117 | + uses: azure/CLI@v1 |
| 118 | + with: |
| 119 | + inlineScript: | |
| 120 | + for file in update_docs/*; do |
| 121 | + blob_name="$(basename "$file")" |
| 122 | + sed -E 's|xref:Connector_help_(.*)$|https://docs.dataminer.services/connector/doc/\1.html|g' $file |
| 123 | + sed -i 's~\~/connector/images/~https://api.dataminer.services/api/public-catalog/v1-0/catalog/images/~g' $file |
| 124 | + az storage blob upload --file "$file" -c 'docs' -n "$blob_name" --connection-string '${{ secrets.AZUREBLOBSTORAGECS }}' --overwrite 'true' |
| 125 | + az storage blob update -c 'docs' -n "$blob_name" --connection-string '${{ secrets.AZUREBLOBSTORAGECS }}' --content-type 'text/plain' |
| 126 | + echo $blob_name uploaded |
| 127 | + done |
| 128 | + |
| 129 | + |
| 130 | + - name: Upload images folder contents to Azure Storage Container |
| 131 | + if: steps.changed-images.outputs.any_changed == 'true' |
| 132 | + uses: azure/CLI@v1 |
| 133 | + with: |
| 134 | + inlineScript: | |
| 135 | + for image in update_images/*; do |
| 136 | + blob_name="$(basename "$image")" |
| 137 | + az storage blob upload --file "$image" -c 'images' -n "$blob_name" --connection-string '${{ secrets.AZUREBLOBSTORAGECS }}' --overwrite 'true' |
| 138 | + echo $blob_name uploaded |
| 139 | + done |
| 140 | +
|
0 commit comments