From e2ad1cd4ef2e5c579f723a50ebe97ce8c463e6ca Mon Sep 17 00:00:00 2001 From: MASES Public Developers Team <94312179+masesdevelopers@users.noreply.github.com> Date: Thu, 27 Jun 2024 02:44:32 +0200 Subject: [PATCH] Update workflows to obtain a PR at the end of reflect_test_commit.yaml which will stimulate docs.yaml and maven.yaml (#184) * Update workflows to obtain a PR at the end of reflect_test_commit.yaml which will stimulate docs.yaml and maven.yaml * Added PR to docs.yaml --- .github/workflows/docs.yaml | 104 +++++++------- .github/workflows/maven.yaml | 57 ++++---- .github/workflows/reflect_test_commit.yaml | 150 +++++++++++++-------- 3 files changed, 175 insertions(+), 136 deletions(-) diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index c6f2e060b4..30492864c4 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -20,40 +20,31 @@ jobs: run_job: ${{ steps.check_files.outputs.run_job }} runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 2 - - - name: check files - id: check_files - run: | - echo "=============== list changed files ===============" - git diff --name-only HEAD^ HEAD - - echo "run_job=false" >> $GITHUB_OUTPUT - echo "========== check paths of changed files ==========" - git diff --name-only HEAD^ HEAD > files.txt - while IFS= read -r file - do - echo $file - if [[ $file == ".github/workflows/docs.yaml"* ]]; then - echo "Recreate docs was requested" - echo "run_job=true" >> $GITHUB_OUTPUT - break - fi - if [[ $file == "src/documentation/"* ]]; then - echo "This file is under the directory 'src/documentation/'." - echo "run_job=true" >> $GITHUB_OUTPUT - break - fi - if [[ $file == "src/jvm/src/"* ]]; then - echo "This file is under the directory 'src/jvm/src/'." - echo "run_job=true" >> $GITHUB_OUTPUT - break - fi - echo "This files are not in a source directory no action required" - done < files.txt + - id: get_changed_files + uses: masesgroup/retrieve-changed-files@v3 + with: + format: 'csv' + + - id: check_files + run: | + mapfile -d ',' -t added_modified_files < <(printf '%s,' '${{ steps.get_changed_files.outputs.added_modified }}') + for added_modified_file in "${added_modified_files[@]}"; do + if [[ $added_modified_file == ".github/workflows/docs.yaml"* ]]; then + echo "$added_modified_file is under the directory '.github/workflows'." + echo "run_job=true" >> $GITHUB_OUTPUT + break + fi + if [[ $added_modified_file == "src/documentation/"* ]]; then + echo "$added_modified_file is under the directory 'src/jvm/src/JCOReflector'." + echo "run_job=true" >> $GITHUB_OUTPUT + break + fi + if [[ $added_modified_file == "src/jvm/src/"* ]]; then + echo "$added_modified_file is under the directory 'src/'." + echo "run_job=true" >> $GITHUB_OUTPUT + break + fi + done # This workflow contains a single job called "build" build_docs: @@ -173,14 +164,14 @@ jobs: env: GITHUB_WORKSPACE: $GITHUB_WORKSPACE - - name: Commit changes to JCOReflector repo - run: | - cd .\docs\ - %GITHUB_WORKSPACE%\.github\workflows\commit.cmd github-actions 41898282+github-actions[bot]@users.noreply.github.com "Update help submodule after commit ${{ env.GITHUB_COMMIT_MESSAGE }}" - cd .. - shell: cmd - env: - GITHUB_WORKSPACE: $GITHUB_WORKSPACE + # - name: Commit changes to JCOReflector repo + # run: | + # cd .\docs\ + # %GITHUB_WORKSPACE%\.github\workflows\commit.cmd github-actions 41898282+github-actions[bot]@users.noreply.github.com "Update help submodule after commit ${{ env.GITHUB_COMMIT_MESSAGE }}" + # cd .. + # shell: cmd + # env: + # GITHUB_WORKSPACE: $GITHUB_WORKSPACE - name: Push changes to net6.0 help file run: | @@ -215,11 +206,24 @@ jobs: SUPER_SECRET: ${{ secrets.DOCS_API_TOKEN_GITHUB }} REPO: masesgroup/FrameworkDocs - - name: Commit changes to JCOReflector - run: | - %GITHUB_WORKSPACE%\.github\workflows\push.cmd %REPO% - shell: cmd - env: - GITHUB_WORKSPACE: $GITHUB_WORKSPACE - SUPER_SECRET: ${{ secrets.DOCS_API_TOKEN_GITHUB }} - REPO: masesgroup/JCOReflector + - name: Request a PR to commit changes + if: ${{ github.repository_owner == 'masesgroup' }} # do not push any changes outside main repo or GeneratePR is false + uses: peter-evans/create-pull-request@v6 + with: + branch-suffix: short-commit-hash + add-paths: .\*.* + commit-message: Update documentation after commit ${{ env.GITHUB_COMMIT_MESSAGE }} + title: Changes by GitHub action + body: Automated changes by GitHub action + reviewers: masesdevelopers + assignees: masesdevelopers + labels: documentation, java, enhancement, .NET Framework, .NET 6, .NET 8 + + # - name: Commit changes to JCOReflector + # run: | + # %GITHUB_WORKSPACE%\.github\workflows\push.cmd %REPO% + # shell: cmd + # env: + # GITHUB_WORKSPACE: $GITHUB_WORKSPACE + # SUPER_SECRET: ${{ secrets.DOCS_API_TOKEN_GITHUB }} + # REPO: masesgroup/JCOReflector diff --git a/.github/workflows/maven.yaml b/.github/workflows/maven.yaml index 75a3a7ad49..92ad8d7525 100644 --- a/.github/workflows/maven.yaml +++ b/.github/workflows/maven.yaml @@ -20,40 +20,31 @@ jobs: run_job: ${{ steps.check_files.outputs.run_job }} runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 2 + - id: get_changed_files + uses: masesgroup/retrieve-changed-files@v3 + with: + format: 'csv' - - name: check files - id: check_files - run: | - echo "=============== list changed files ===============" - git diff --name-only HEAD^ HEAD - - echo "run_job=false" >> $GITHUB_OUTPUT - echo "========== check paths of changed files ==========" - git diff --name-only HEAD^ HEAD > files.txt - while IFS= read -r file - do - echo $file - if [[ $file == ".github/workflows/maven.yaml"* ]]; then - echo "A change in workflow was made, a run is requested" - echo "run_job=true" >> $GITHUB_OUTPUT - break - fi - if [[ $file == "src/engine/JCOPOMJCOReflector.template"* ]]; then - echo "A change in template was made, a run is requested" - echo "run_job=true" >> $GITHUB_OUTPUT - break - fi - if [[ $file == "src/jvm/src/"* ]]; then - echo "This file is under the directory 'src/jvm/src/'." - echo "run_job=true" >> $GITHUB_OUTPUT - break - fi - echo "This files are not in a source directory no action required" - done < files.txt + - id: check_files + run: | + mapfile -d ',' -t added_modified_files < <(printf '%s,' '${{ steps.get_changed_files.outputs.added_modified }}') + for added_modified_file in "${added_modified_files[@]}"; do + if [[ $added_modified_file == ".github/workflows/maven.yaml"* ]]; then + echo "$added_modified_file is under the directory '.github/workflows'." + echo "run_job=true" >> $GITHUB_OUTPUT + break + fi + if [[ $added_modified_file == "src/engine/JCOPOMJCOReflector.template"* ]]; then + echo "$added_modified_file is under the directory 'src/jvm/src/JCOReflector'." + echo "run_job=true" >> $GITHUB_OUTPUT + break + fi + if [[ $added_modified_file == "src/jvm/src/"* ]]; then + echo "$added_modified_file is under the directory 'src/'." + echo "run_job=true" >> $GITHUB_OUTPUT + break + fi + done # This workflow contains a single job called "build" build_maven: diff --git a/.github/workflows/reflect_test_commit.yaml b/.github/workflows/reflect_test_commit.yaml index 5b3054e6d6..cc3e556800 100644 --- a/.github/workflows/reflect_test_commit.yaml +++ b/.github/workflows/reflect_test_commit.yaml @@ -135,14 +135,14 @@ jobs: with: enableCrossOsArchive: true path: ./src/jvm/ - key: JCOReflector_source_${{ github.sha }} + key: JCOReflector_${{ github.run_number }}_${{ github.run_attempt }}_source_${{ github.sha }} - name: Save JCOReflector bin in cache uses: actions/cache/save@v4 with: enableCrossOsArchive: true path: ./bin/ - key: JCOReflector_windows_bin_${{ github.sha }} + key: JCOReflector_${{ github.run_number }}_${{ github.run_attempt }}_windows_bin_${{ github.sha }} # This workflow contains a single job called "build" build_linux: @@ -163,7 +163,7 @@ jobs: fail-on-cache-miss: true enableCrossOsArchive: true path: ./src/jvm/ - key: JCOReflector_source_${{ github.sha }} + key: JCOReflector_${{ github.run_number }}_${{ github.run_attempt }}_source_${{ github.sha }} # Runs a set of commands using the runners shell - name: Build JCOReflectorCLI @@ -193,7 +193,7 @@ jobs: with: enableCrossOsArchive: true path: ./bin/ - key: JCOReflector_linux_bin_${{ github.sha }} + key: JCOReflector_${{ github.run_number }}_${{ github.run_attempt }}_linux_bin_${{ github.sha }} execute_java_tests_windows: needs: build_windows @@ -226,7 +226,7 @@ jobs: fail-on-cache-miss: true enableCrossOsArchive: true path: ./bin/ - key: JCOReflector_windows_bin_${{ github.sha }} + key: JCOReflector_${{ github.run_number }}_${{ github.run_attempt }}_windows_bin_${{ github.sha }} - name: Set up JDK distribution uses: actions/setup-java@v4 @@ -331,7 +331,7 @@ jobs: fail-on-cache-miss: true enableCrossOsArchive: true path: ./bin/ - key: JCOReflector_windows_bin_${{ github.sha }} + key: JCOReflector_${{ github.run_number }}_${{ github.run_attempt }}_windows_bin_${{ github.sha }} - name: Set up JDK distribution uses: actions/setup-java@v4 @@ -452,7 +452,7 @@ jobs: fail-on-cache-miss: true enableCrossOsArchive: true path: ./bin/ - key: JCOReflector_linux_bin_${{ github.sha }} + key: JCOReflector_${{ github.run_number }}_${{ github.run_attempt }}_linux_bin_${{ github.sha }} - name: Set up JDK distribution uses: actions/setup-java@v4 @@ -544,7 +544,7 @@ jobs: fail-on-cache-miss: true enableCrossOsArchive: true path: ./bin/ - key: JCOReflector_linux_bin_${{ github.sha }} + key: JCOReflector_${{ github.run_number }}_${{ github.run_attempt }}_linux_bin_${{ github.sha }} - name: Set up JDK distribution uses: actions/setup-java@v4 @@ -661,7 +661,7 @@ jobs: fail-on-cache-miss: true enableCrossOsArchive: true path: ./bin/ - key: JCOReflector_linux_bin_${{ github.sha }} + key: JCOReflector_${{ github.run_number }}_${{ github.run_attempt }}_linux_bin_${{ github.sha }} - name: Set up JDK distribution uses: actions/setup-java@v4 @@ -775,7 +775,7 @@ jobs: fail-on-cache-miss: true enableCrossOsArchive: true path: ./bin/ - key: JCOReflector_windows_bin_${{ github.sha }} + key: JCOReflector_${{ github.run_number }}_${{ github.run_attempt }}_windows_bin_${{ github.sha }} - name: Restore JCOReflector source from cache uses: actions/cache/restore@v4 @@ -783,7 +783,7 @@ jobs: fail-on-cache-miss: true enableCrossOsArchive: true path: ./src/jvm/ - key: JCOReflector_source_${{ github.sha }} + key: JCOReflector_${{ github.run_number }}_${{ github.run_attempt }}_source_${{ github.sha }} - name: Compress release files run: | @@ -796,49 +796,66 @@ jobs: echo "GITHUB_COMMIT_MESSAGE=$(echo $GITHUB_SHA | cut -c 1-7)" >> $GITHUB_ENV shell: bash - - name: Commit statistics changes - if: ${{ github.repository_owner == 'masesgroup'}} #do not push any changes outside main repo - uses: EndBug/add-and-commit@v9 + - name: Request a PR to commit changes + if: ${{ github.repository_owner == 'masesgroup' }} # do not push any changes outside main repo or GeneratePR is false + uses: peter-evans/create-pull-request@v6 with: - author_name: github-actions - author_email: 41898282+github-actions[bot]@users.noreply.github.com - add: '.\src\jvm\statistics\*.*' - message: Update statistics after commit ${{ env.GITHUB_COMMIT_MESSAGE }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Commit report changes - if: ${{ github.repository_owner == 'masesgroup'}} #do not push any changes outside main repo - uses: EndBug/add-and-commit@v9 - with: - author_name: github-actions - author_email: 41898282+github-actions[bot]@users.noreply.github.com - add: '.\src\jvm\README.md' - message: Update README.md after commit ${{ env.GITHUB_COMMIT_MESSAGE }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Commit source changes - if: ${{ github.repository_owner == 'masesgroup'}} #do not push any changes outside main repo - uses: EndBug/add-and-commit@v9 - with: - author_name: github-actions - author_email: 41898282+github-actions[bot]@users.noreply.github.com - add: '.\src\jvm\src\*.list' - message: Update assembly list after commit ${{ env.GITHUB_COMMIT_MESSAGE }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Commit source changes - if: ${{ github.repository_owner == 'masesgroup'}} #do not push any changes outside main repo - uses: EndBug/add-and-commit@v9 - with: - author_name: github-actions - author_email: 41898282+github-actions[bot]@users.noreply.github.com - add: '.\src\jvm\src\*.java' - message: Update sources after commit ${{ env.GITHUB_COMMIT_MESSAGE }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + branch-suffix: short-commit-hash + add-paths: | + .\src\jvm\statistics\*.* + .\src\jvm\README.md + .\src\jvm\src\*.list + .\src\jvm\src\*.java + commit-message: Update JVM after commit ${{ env.GITHUB_COMMIT_MESSAGE }} + title: Changes by GitHub action + body: Automated changes by GitHub action + reviewers: masesdevelopers + assignees: masesdevelopers + labels: enhancement, java, .NET Framework, .NET 6, .NET 8 + + # - name: Commit statistics changes + # if: ${{ github.repository_owner == 'masesgroup'}} #do not push any changes outside main repo + # uses: EndBug/add-and-commit@v9 + # with: + # author_name: github-actions + # author_email: 41898282+github-actions[bot]@users.noreply.github.com + # add: '.\src\jvm\statistics\*.*' + # message: Update statistics after commit ${{ env.GITHUB_COMMIT_MESSAGE }} + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # + # - name: Commit report changes + # if: ${{ github.repository_owner == 'masesgroup'}} #do not push any changes outside main repo + # uses: EndBug/add-and-commit@v9 + # with: + # author_name: github-actions + # author_email: 41898282+github-actions[bot]@users.noreply.github.com + # add: '.\src\jvm\README.md' + # message: Update README.md after commit ${{ env.GITHUB_COMMIT_MESSAGE }} + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # + # - name: Commit source changes + # if: ${{ github.repository_owner == 'masesgroup'}} #do not push any changes outside main repo + # uses: EndBug/add-and-commit@v9 + # with: + # author_name: github-actions + # author_email: 41898282+github-actions[bot]@users.noreply.github.com + # add: '.\src\jvm\src\*.list' + # message: Update assembly list after commit ${{ env.GITHUB_COMMIT_MESSAGE }} + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # + # - name: Commit source changes + # if: ${{ github.repository_owner == 'masesgroup'}} #do not push any changes outside main repo + # uses: EndBug/add-and-commit@v9 + # with: + # author_name: github-actions + # author_email: 41898282+github-actions[bot]@users.noreply.github.com + # add: '.\src\jvm\src\*.java' + # message: Update sources after commit ${{ env.GITHUB_COMMIT_MESSAGE }} + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - uses: actions/upload-artifact@v4 with: @@ -859,3 +876,30 @@ jobs: with: name: net462 path: .\bin\net462.zip + + final_cleanup: + needs: [ execute_finalize ] + if: "always()" + runs-on: ubuntu-latest + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v4 + with: + fetch-depth: '1' + + - name: Clear caches + run: | + gh extension install actions/gh-actions-cache + echo "Fetching list of cache key" + cacheKeysForPR=$(gh actions-cache list --key JCOReflector_${{ github.run_number }}_${{ github.run_attempt }} ) + ## Setting this to not fail the workflow while deleting cache keys. + set +e + echo "Deleting caches..." + for cacheKey in $cacheKeysForPR + do + gh actions-cache delete $cacheKey --confirm + done + echo "Done" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file