From cfe4f821c956610178cc2886e930650c2f2e6b92 Mon Sep 17 00:00:00 2001 From: zack Date: Sat, 19 Oct 2024 23:08:21 -0400 Subject: [PATCH] updates --- .github/actions/create-hydra-jobset.yml | 79 +++++++++++++++++++++++++ .github/workflows/update.yml | 26 ++++++++ 2 files changed, 105 insertions(+) create mode 100644 .github/actions/create-hydra-jobset.yml diff --git a/.github/actions/create-hydra-jobset.yml b/.github/actions/create-hydra-jobset.yml new file mode 100644 index 0000000..e149077 --- /dev/null +++ b/.github/actions/create-hydra-jobset.yml @@ -0,0 +1,79 @@ +name: 'Create Hydra Jobset' +description: 'Creates or updates a jobset on a Hydra CI server' +inputs: + hydra_instance: + description: 'URL of the Hydra instance' + required: true + hydra_project: + description: 'Name of the Hydra project' + required: true + hydra_jobset: + description: 'Name of the Hydra jobset' + required: true + hydra_username: + description: 'Username for Hydra authentication' + required: true + hydra_password: + description: 'Password for Hydra authentication' + required: true + flake_uri: + description: 'URI of the flake to build' + required: true + description: + description: 'Description of the jobset' + required: false + default: 'Auto-created jobset' + enabled: + description: 'Whether the jobset should be enabled' + required: false + default: '1' + visible: + description: 'Whether the jobset should be visible' + required: false + default: '0' + keepnr: + description: 'Number of builds to keep' + required: false + default: '3' + checkinterval: + description: 'Interval between checks in seconds' + required: false + default: '300' + +runs: + using: "composite" + steps: + - name: Create or update Hydra jobset + shell: bash + run: | + AUTH_HEADER="Authorization: Basic $(echo -n '${{ inputs.hydra_username }}:${{ inputs.hydra_password }}' | base64)" + + # Prepare the JSON payload + payload=$(cat << EOF + { + "enabled": ${{ inputs.enabled }}, + "visible": ${{ inputs.visible }}, + "keepnr": ${{ inputs.keepnr }}, + "checkinterval": ${{ inputs.checkinterval }}, + "description": "${{ inputs.description }}", + "flake": "${{ inputs.flake_uri }}", + "type": 1 + } + EOF + ) + + # Send the request to create or update the jobset + response=$(curl -s -X PUT \ + -H "Content-Type: application/json" \ + -H "$AUTH_HEADER" \ + -d "$payload" \ + "${{ inputs.hydra_instance }}/jobset/${{ inputs.hydra_project }}/${{ inputs.hydra_jobset }}") + + # Check the response + if [[ $response == *"\"jobset\":\"${{ inputs.hydra_jobset }}\""* ]]; then + echo "Hydra jobset created or updated successfully" + else + echo "Failed to create or update Hydra jobset" + echo "Response: $response" + exit 1 + fi diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index b70c163..427b5d8 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -77,6 +77,18 @@ jobs: --base main \ --head ${{ env.BRANCH_NAME }} + - name: Create Hydra jobset + if: steps.update-flake.outputs.CHANGED == 'true' + uses: ./.github/actions/create-hydra-jobset + with: + hydra_instance: ${{ env.HYDRA_INSTANCE }} + hydra_project: ${{ env.HYDRA_PROJECT }} + hydra_jobset: ${{ env.HYDRA_JOBSET }} + hydra_username: ${{ secrets.HYDRA_USERNAME }} + hydra_password: ${{ secrets.HYDRA_PASSWORD }} + flake_uri: "github:${{ github.repository }}/${{ env.BRANCH_NAME }}" + description: "PR #${{ steps.create-pr.outputs.pr_number }} - Auto-update flake dependencies" + - name: Trigger Hydra build if: steps.update-flake.outputs.CHANGED == 'true' uses: ./.github/actions/trigger-hydra-build @@ -98,6 +110,13 @@ jobs: hydra_username: ${{ secrets.HYDRA_USERNAME }} hydra_password: ${{ secrets.HYDRA_PASSWORD }} + - name: Approve PR + if: steps.update-flake.outputs.CHANGED == 'true' && steps.wait-for-build.outputs.BUILD_SUCCESS == 'true' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh pr review ${{ steps.create-pr.outputs.pr_number }} --approve --body "Automated approval: Hydra build succeeded" + - name: Merge PR if build succeeds if: steps.update-flake.outputs.CHANGED == 'true' && steps.wait-for-build.outputs.BUILD_SUCCESS == 'true' env: @@ -168,6 +187,13 @@ jobs: hydra_username: ${{ secrets.HYDRA_USERNAME }} hydra_password: ${{ secrets.HYDRA_PASSWORD }} + - name: Approve PR + if: steps.update-flake.outputs.CHANGED == 'true' && steps.wait-for-build.outputs.BUILD_SUCCESS == 'true' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh pr review ${{ needs.check-existing-pr.outputs.pr_number }} --approve --body "Automated approval: Hydra build succeeded" + - name: Merge PR if build succeeds if: steps.update-flake.outputs.CHANGED == 'true' && steps.wait-for-build.outputs.BUILD_SUCCESS == 'true' env: