From 5954a8c0c9313a6872bbd45b8566a51072e81db1 Mon Sep 17 00:00:00 2001 From: Alexander Schramm Date: Fri, 17 May 2024 15:27:39 +0200 Subject: [PATCH] Outsource Github Workflows --- .github/workflows/build_main.yml | 73 ++----------------- .github/workflows/build_pr.yml | 36 +-------- .github/workflows/build_releasecandidate.yml | 77 +------------------- .github/workflows/update_pr_with_comment.yml | 65 +---------------- 4 files changed, 14 insertions(+), 237 deletions(-) diff --git a/.github/workflows/build_main.yml b/.github/workflows/build_main.yml index 42d2277..4c8ffe1 100644 --- a/.github/workflows/build_main.yml +++ b/.github/workflows/build_main.yml @@ -6,75 +6,12 @@ name: CI - Releases and Main # events but only for the main branch on: push: - branches: [ main ] + branches: [ main, outsource_workflows ] tags: - "[2-9][0-9][0-9][0-9].[0-9]+-rev[0-9]+" -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - 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 - - name: Checkout Source - uses: actions/checkout@v3 - with: - submodules: recursive - - name: Verify Gradle Wrapper - uses: gradle/wrapper-validation-action@v1 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: 17 - - # If we're building a release, we need to set the variable RELEASE_VERSION - - name: Set Environment Variables for Release Version - if: startsWith(github.ref, 'refs/tags/') - run: echo "RELEASE_VERSION=${GITHUB_REF:10}" >> $GITHUB_ENV - - - name: Execute Gradle Build - uses: gradle/gradle-build-action@v2 - env: - CI: true - with: - gradle-version: wrapper - arguments: buildDocs - - # release and deploy only if we're building a release - - name: Prepare Deployment - if: startsWith(github.ref, 'refs/tags/') - run: | - rm -rf ./build/tmp - cp ./docs-ext/curriculum-*.pdf ./build 2>/dev/null || : - zip -r release.zip ./build - mkdir release_dir - cp ./build/curriculum-*.pdf ./release_dir 2>/dev/null || : - mv release.zip ./release_dir/release-${{ env.RELEASE_VERSION }}.zip - - name: Create New Release - if: startsWith(github.ref, 'refs/tags/') - id: create-release - uses: ncipollo/release-action@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token - with: - tag: ${{ env.RELEASE_VERSION }} - name: Release ${{ env.RELEASE_VERSION }} - draft: false - prerelease: false - bodyFile: "CHANGELOG.md" - artifacts: "license-copyright/LICENSE.adoc,release_dir/*.pdf,release_dir/*.zip" - token: ${{ secrets.GITHUB_TOKEN }} - - name: Deploy - if: startsWith(github.ref, 'refs/tags/') - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./build - user_name: 'github-actions[bot]' - user_email: 'github-actions[bot]@users.noreply.github.com' - commit_message: Publish Release ${{ env.RELEASE_VERSION }} + call_workflow_build: + uses: isaqb-org/github-workflows/.github/workflows/build_main.yml@main + with: + release_version: env.RELEASE_VERSION diff --git a/.github/workflows/build_pr.yml b/.github/workflows/build_pr.yml index a1d0aa0..df494bc 100644 --- a/.github/workflows/build_pr.yml +++ b/.github/workflows/build_pr.yml @@ -7,37 +7,7 @@ name: CI – Pull Requests on: pull_request: branches: [ main ] -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - 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 - - name: checkout source - uses: actions/checkout@v3 - with: - submodules: recursive - - name: Verify Gradle Wrapper - uses: gradle/wrapper-validation-action@v1 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: 17 - - name: Execute Gradle Build - uses: gradle/gradle-build-action@v2 - with: - gradle-version: wrapper - arguments: buildDocs - - name: Upload Build Artifacts - uses: actions/upload-artifact@v3 - with: - name: curriculum files (PDF and HTML) - path: | - build/*.pdf - build/*.html - retention-days: 10 +jobs: + call_workflow_build_pr: + uses: isaqb-org/github-workflows/.github/workflows/build_pr.yml@main diff --git a/.github/workflows/build_releasecandidate.yml b/.github/workflows/build_releasecandidate.yml index 005b42d..88d7af4 100644 --- a/.github/workflows/build_releasecandidate.yml +++ b/.github/workflows/build_releasecandidate.yml @@ -9,77 +9,8 @@ on: tags: - "[2-9][0-9][0-9][0-9].[0-9]+-RC[0-9]+" -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - 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 - - name: Checkout Source - uses: actions/checkout@v3 - with: - submodules: recursive - - name: Update index.adoc - run: | - rm docs/index.adoc - mv docs/index_rc.adoc docs/index.adoc - - name: Verify Gradle Wrapper - uses: gradle/wrapper-validation-action@v1 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: 17 - - # If we're building a release, we need to set the variable RELEASE_VERSION - - name: Set Environment Variables for Release Version - if: startsWith(github.ref, 'refs/tags/') - run: echo "RELEASE_VERSION=${GITHUB_REF:10}" >> $GITHUB_ENV - - - name: Execute Gradle Build - uses: gradle/gradle-build-action@v2 - env: - CI: true - with: - gradle-version: wrapper - arguments: buildDocs - - # do the following two things only for a release! - - name: Prepare Deployment - if: startsWith(github.ref, 'refs/tags/') - run: | - rm -rf ./build/tmp - cp ./docs-ext/curriculum-*.pdf ./build 2>/dev/null || : - zip -r release.zip ./build - mkdir release_dir - cp ./build/curriculum-*.pdf ./release_dir 2>/dev/null || : - mv release.zip ./release_dir/release-${{ env.RELEASE_VERSION }}.zip - - name: Create New Release Candidate - if: startsWith(github.ref, 'refs/tags/') - id: create-release-candidate - uses: ncipollo/release-action@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token - with: - tag: ${{ env.RELEASE_VERSION }} - name: Release Candidate ${{ env.RELEASE_VERSION }} - draft: false - prerelease: true - bodyFile: "CHANGELOG.md" - artifacts: "license-copyright/LICENSE.adoc,release_dir/*.pdf,release_dir/*.zip" - token: ${{ secrets.GITHUB_TOKEN }} - - name: Deploy Release Candidate to GitHub Pages - if: startsWith(github.ref, 'refs/tags/') - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./build - destination_dir: release-candidate - keep_files: true - user_name: 'github-actions[bot]' - user_email: 'github-actions[bot]@users.noreply.github.com' - commit_message: Publish Release Candidate ${{ env.RELEASE_VERSION }} + call_workflow_build_pr: + uses: isaqb-org/github-workflows/.github/workflows/build_releasecandidate.yml@main + with: + release_version: env.RELEASE_VERSION diff --git a/.github/workflows/update_pr_with_comment.yml b/.github/workflows/update_pr_with_comment.yml index 172c879..539e577 100644 --- a/.github/workflows/update_pr_with_comment.yml +++ b/.github/workflows/update_pr_with_comment.yml @@ -6,66 +6,5 @@ on: workflows: [CI – Pull Requests] jobs: - comment: - if: ${{ github.event.workflow_run.conclusion == 'success' }} && ${{github.event_name == 'pull_request' }} - runs-on: ubuntu-latest - steps: - - name: Get Artifact and Pull request info - env: - GITHUB_TOKEN: ${{ github.token }} - WORKFLOW_RUN_EVENT_OBJ: ${{ toJSON(github.event.workflow_run) }} - OWNER: ${{ github.repository_owner }} - REPO: ${{ github.event.repository.name }} - run: | - PREVIOUS_JOB_ID=$(jq -r '.id' <<< "$WORKFLOW_RUN_EVENT_OBJ") - echo "Previous Job ID: $PREVIOUS_JOB_ID" - echo "PREVIOUS_JOB_ID=$PREVIOUS_JOB_ID" >> "$GITHUB_ENV" - - SUITE_ID=$(jq -r '.check_suite_id' <<< "$WORKFLOW_RUN_EVENT_OBJ") - echo "Previous Suite ID: $SUITE_ID" - echo "SUITE_ID=$SUITE_ID" >> "$GITHUB_ENV" - - ARTIFACT_ID=$(gh api "/repos/$OWNER/$REPO/actions/artifacts" \ - --jq ".artifacts.[] | - select(.workflow_run.id==${PREVIOUS_JOB_ID}) | - select(.expired==false) | - .id") - - echo "Artifact ID: $ARTIFACT_ID" - echo "ARTIFACT_ID=$ARTIFACT_ID" >> "$GITHUB_ENV" - - PR_NUMBER=$(jq -r '.pull_requests[0].number' \ - <<< "$WORKFLOW_RUN_EVENT_OBJ") - - echo "Pull request Number: $PR_NUMBER" - echo "PR_NUMBER=$PR_NUMBER" >> "$GITHUB_ENV" - - HEAD_SHA=$(jq -r '.pull_requests[0].head.sha' \ - <<< "$WORKFLOW_RUN_EVENT_OBJ") - - echo "Head SHA: $HEAD_SHA" - echo "HEAD_SHA=$HEAD_SHA" >> "$GITHUB_ENV" - - name: Find Comment - uses: peter-evans/find-comment@v2 - id: find-comment - with: - issue-number: ${{ env.PR_NUMBER }} - comment-author: 'github-actions[bot]' - - name: Update Comment - env: - JOB_PATH: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ env.PREVIOUS_JOB_ID }}" - ARTIFACT_URL: "${{ github.server_url }}/${{ github.repository }}/suites/${{ env.SUITE_ID }}/artifacts/${{ env.ARTIFACT_ID }}" - HEAD_SHA: "${{ env.HEAD_SHA }}" - uses: peter-evans/create-or-update-comment@v3 - with: - issue-number: ${{ env.PR_NUMBER }} - comment-id: ${{ steps.find-comment.outputs.comment-id }} - edit-mode: replace - body: |- - Build Successful! You can find a link to the downloadable artifacts below. - - | Name | Link | - | -------- | ----------------------- | - | Commit | ${{ env.HEAD_SHA }} | - | Logs | ${{ env.JOB_PATH }} | - | Download | ${{ env.ARTIFACT_URL }} | + call_workflow_build: + uses: isaqb-org/github-workflows/.github/workflows/update_pr_with_comment.yml@main