From 254fe61310e76b578d531327baeb5126f49868c1 Mon Sep 17 00:00:00 2001 From: masesdevelopers <94312179+masesdevelopers@users.noreply.github.com> Date: Thu, 27 Jun 2024 02:27:40 +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 --- .github/workflows/docs.yaml | 59 ++++---- .github/workflows/maven.yaml | 57 ++++---- .github/workflows/reflect_test_commit.yaml | 150 +++++++++++++-------- 3 files changed, 146 insertions(+), 120 deletions(-) diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index c6f2e060b4..d62cd784db 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: 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..d8db563422 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: java, documentation, enhancement, .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