From 2e6569f0165c0bc4bcee76ba7f434b8a5668d5ce Mon Sep 17 00:00:00 2001 From: Peter Palaga Date: Thu, 14 Mar 2024 16:38:00 +0100 Subject: [PATCH] Add quarkus-main rebase workflow --- .../rebase-dependency-main-branch/action.yml | 93 +++++++++++++++++++ .github/actions/update-issue/action.yml | 39 ++++++++ .github/workflows/quarkus-main-rebase.yml | 60 ++++++++++++ 3 files changed, 192 insertions(+) create mode 100644 .github/actions/rebase-dependency-main-branch/action.yml create mode 100644 .github/actions/update-issue/action.yml create mode 100644 .github/workflows/quarkus-main-rebase.yml diff --git a/.github/actions/rebase-dependency-main-branch/action.yml b/.github/actions/rebase-dependency-main-branch/action.yml new file mode 100644 index 000000000..ddb31b4ee --- /dev/null +++ b/.github/actions/rebase-dependency-main-branch/action.yml @@ -0,0 +1,93 @@ +name: rebase-dependency-main-branch +description: 'Rebase a dependency main branch such as quarkus-main or cxf-main, rebuild it and report the status in a dedicated issue' + +inputs: + java-version: + description: 'Java version' + required: true + dependency-git-repo-url: + description: "The URL of the dependency's git repository to checkout and build from" + required: true + dependency-short-name: + description: "The short lower case name of the dependency as quarkus or cxf" + required: true + issue-id: + description: "The issue number where to report any rebase or build issues" + required: true + token: + description: "The token to use to authenticate against GitHub API" + required: true + additional-maven-args: + description: "Additional arguments to append to mvn install -ntp" + required: true + +outputs: + dependency-commit: + description: "The SHA1 of the dependency main branch" + value: ${{ steps.checkout-dependency.outputs.dependency-commit }} + dependency-version: + description: "The version of the dependency as present in the top pom.xml of its main branch" + value: ${{ steps.checkout-dependency.outputs.dependency-version }} + +runs: + using: 'composite' + steps: + - uses: actions/checkout@v4 + + - name: rebase ${{ inputs.dependency-short-name }}-main + shell: bash + run: | + echo "GH_ISSUE_STATE=closed" >> $GITHUB_ENV + set -e + git fetch origin + git checkout ${{ inputs.dependency-short-name }}-main 2>/dev/null || git checkout -b ${{ inputs.dependency-short-name }}-main + git rebase origin/main \ + || ( echo "GH_ISSUE_MESSAGE=Could not rebase ${{ inputs.dependency-short-name }}-main in ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> $GITHUB_ENV \ + && echo "GH_ISSUE_STATE=open" >> $GITHUB_ENV ) + + - name: test the output + shell: bash + run: | + echo "${{ env.GH_ISSUE_MESSAGE }}" + echo "${{ env.GH_ISSUE_STATE }}" + + - name: update-issue + uses: ./.github/actions/update-issue + with: + issue-id: "${{ env.ISSUE_ID }}" + token: "${{ inputs.token }}" + add-message: "${{ env.GH_ISSUE_MESSAGE }}" + new-state: "${{ env.GH_ISSUE_STATE }}" + + - name: Make the current workflow fail + shell: bash + if: env.GH_ISSUE_STATE == 'open' + run: | + exit 1 + + - name: Checkout ${{ inputs.dependency-git-repo-url }} + id: checkout-dependency + shell: bash + run: | + repoName="$(basename -s .git "${{ inputs.dependency-git-repo-url }}")" + cd ~ + [[ -d "$repoName" ]] || git clone --depth 1 --branch main ${{ inputs.dependency-git-repo-url }} + cd $repoName \ + && echo "Current $repoName commit:" $(git rev-parse HEAD) \ + && echo "dependency-commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT + && echo "dependency-version=$(xmllint --xpath "/*[local-name() = 'project']/*[local-name() = 'version']/text()" pom.xml)" >> $GITHUB_OUTPUT + + - name: Set ${{ inputs.dependency-short-name }}.version to ${{ steps.checkout-dependency.outputs.dependency-version }} + shell: bash + run: | + sed -i 's|<${{ inputs.dependency-short-name }}.version>\[^<\]*|<${{ inputs.dependency-short-name }}.version>${{ steps.checkout-dependency.outputs.dependency-version }}|' pom.xml + if git diff-index --quiet HEAD --; then + echo "${{ inputs.dependency-short-name }}-main uses version ${{ steps.checkout-dependency.outputs.dependency-version }} already" + ./mvnw cq:sync-versions -Dcq.simpleElementWhitespace=AUTODETECT_PREFER_SPACE -N + git add -A + git commit -m "Re-run mvn cq:sync-versions" + else + ./mvnw cq:sync-versions -Dcq.simpleElementWhitespace=AUTODETECT_PREFER_SPACE -N + git add -A + git commit -m "Upgrade ${{ inputs.dependency-short-name }}.version to ${{ steps.checkout-dependency.outputs.dependency-version }}" + fi diff --git a/.github/actions/update-issue/action.yml b/.github/actions/update-issue/action.yml new file mode 100644 index 000000000..ac5a3950c --- /dev/null +++ b/.github/actions/update-issue/action.yml @@ -0,0 +1,39 @@ +name: update-issue +description: 'Update the status of a specific issue and optionally add a message' + +inputs: + issue-id: + description: "The number of the issue to update" + required: true + token: + description: "The token to use to authenticate against GitHub API" + required: true + add-message: + description: "The message body to add" + required: true + default: '' + new-state: + description: "The new issue state to set" + required: true + +runs: + using: 'composite' + steps: + + - name: Add message to issue ${{ inputs.issue-id }} + if: inputs.add-message != '' + uses: peter-evans/create-or-update-comment@v4 + with: + token: ${{ inputs.token }} + issue-number: ${{ inputs.issue-id }} + body: | + ${{ inputs.add-message }} + + - name: Update the status of issue ${{ inputs.issue-id }} + shell: bash + run: | + curl --request PATCH \ + --url ${{ github.api_url }}/repos/${{ github.repository }}/issues/${{ inputs.issue-id }} \ + --header 'Authorization: token ${{ inputs.token }}' \ + --header 'Content-Type: application/json' \ + --data '{"state": "${{ inputs.new-state }}"}' diff --git a/.github/workflows/quarkus-main-rebase.yml b/.github/workflows/quarkus-main-rebase.yml new file mode 100644 index 000000000..a443d6f1e --- /dev/null +++ b/.github/workflows/quarkus-main-rebase.yml @@ -0,0 +1,60 @@ +name: quarkus-main rebase + +on: + workflow_dispatch: + schedule: + # Run every day at 2AM + - cron: '0 2 * * *' + +env: + LANG: en_US.UTF-8 + ISSUE_ID: 1287 + DEPENDENCY_SHORT_NAME: quarkus + +concurrency: + group: ${{ github.ref }}-${{ github.workflow }} + cancel-in-progress: true + +jobs: + rebase-quarkus-main: + if: github.repository == 'quarkiverse/quarkus-cxf' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: rebase-dependency-main-branch + uses: ./.github/actions/rebase-dependency-main-branch + id: rebase-dependency-main-branch + with: + java-version: ${{ env.JAVA_VERSION }} + dependency-git-repo-url: https://github.com/quarkusio/quarkus.git + dependency-short-name: ${{ env.DEPENDENCY_SHORT_NAME }} + issue-id: ${{ env.ISSUE_ID }} + token: "${{ secrets.QUARKIVERSEBOT_TOKEN }}" + additional-maven-args: '-DskipTests -Dcheckstyle.skip' + + - name: build-and-run-jvm-tests + uses: ./.github/actions/build-and-run-jvm-tests + with: + java-version: ${{ env.JAVA_VERSION }} + + - name: push origin ${{ env.DEPENDENCY_SHORT_NAME }}-main -f + shell: bash + run: | + push origin ${{ env.DEPENDENCY_SHORT_NAME }}-main -f + + - name: Update issue ${{ env.ISSUE_ID }} + if: ${{ failure() }} + uses: ./.github/actions/update-issue + with: + issue-id: "${{ env.ISSUE_ID }}" + add-message: "Build with ${{ env.DEPENDENCY_SHORT_NAME }} ${{ steps.rebase-dependency-main-branch.outputs.dependency-commit }} failed in ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" + new-state: "open" + + - name: Update issue ${{ env.ISSUE_ID }} + if: ${{ success() }} + uses: ./.github/actions/update-issue + with: + issue-id: "${{ env.ISSUE_ID }}" + token: "${{ secrets.QUARKIVERSEBOT_TOKEN }}" + new-state: "closed"