From af7d521bfc3ec0c57d697e6a7d23a8b5672c7ea7 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 9 Mar 2024 07:41:47 +0100 Subject: [PATCH] Download documentation in amd64 build and further reduce code duplication Signed-off-by: DL6ER --- .github/actions/build-and-test/action.yml | 33 +++++++++++++++++++ .github/actions/deploy/action.yml | 14 +++++++- .github/workflows/build.yml | 39 ++++++----------------- 3 files changed, 55 insertions(+), 31 deletions(-) diff --git a/.github/actions/build-and-test/action.yml b/.github/actions/build-and-test/action.yml index a03beade..231e43bd 100644 --- a/.github/actions/build-and-test/action.yml +++ b/.github/actions/build-and-test/action.yml @@ -20,6 +20,26 @@ inputs: event_name: required: true description: The name of the event that triggered the workflow run + actor: + required: true + description: The name of the user or app that initiated the workflow run + target_dir: + required: true + description: The directory to deploy the artifacts to + # Secrets cannot be accessed in the action.yml file so we need to pass them as + # inputs to the action. + SSH_KEY: + required: true + description: The SSH private key to use for authentication + KNOWN_HOSTS: + required: true + description: The SSH known hosts file + SSH_USER: + required: true + description: The SSH user to use for authentication + SSH_HOST: + required: true + description: The SSH host to connect to # Both the definition of environment variables and checking out the code # needs to be done outside of the composite action as @@ -91,3 +111,16 @@ runs: with: name: pihole-api-docs path: 'api-docs.tar.gz' + - + name: Deploy + if: inputs.event_name != 'pull_request' + uses: ./.github/actions/deploy + with: + pattern: ${{ inputs.bin_name }}-binary + target_dir: ${{ inputs.target_dir }} + event_name: ${{ inputs.event_name }} + actor: ${{ inputs.actor }} + SSH_KEY: ${{ inputs.SSH_KEY }} + KNOWN_HOSTS: ${{ inputs.KNOWN_HOSTS }} + SSH_USER: ${{ inputs.SSH_USER }} + SSH_HOST: ${{ inputs.SSH_HOST }} diff --git a/.github/actions/deploy/action.yml b/.github/actions/deploy/action.yml index ccf0be77..0d60da68 100644 --- a/.github/actions/deploy/action.yml +++ b/.github/actions/deploy/action.yml @@ -33,13 +33,20 @@ runs: using: "composite" steps: - - name: Get binaries (and possibly documentation) built in previous jobs + name: Get binaries built in previous jobs uses: actions/download-artifact@v4.1.4 id: download with: path: ftl_builds/ pattern: ${{ inputs.pattern }} merge-multiple: true + - + name: Get documentation files built in previous jobs + if: inputs.pattern == 'pihole-FTL-amd64-binary' + uses: actions/download-artifact@v4.1.4 + with: + path: ftl_builds/ + name: pihole-api-docs - name: Display structure of downloaded files shell: bash @@ -50,7 +57,12 @@ runs: uses: benoitchantre/setup-ssh-authentication-action@1.0.1 with: private-key: ${{ inputs.SSH_KEY }} + private-key-name: id_rsa known-hosts: ${{ inputs.KNOWN_HOSTS }} + - + name: Set private key permissions + shell: bash + run: chmod 600 ~/.ssh/id_rsa - name: Untar documentation files if: inputs.pattern == 'pihole-FTL-amd64-binary' diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4b09782b..1966c7c1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,7 +50,7 @@ jobs: [[ $FAIL == 1 ]] && exit 1 || echo "Branch name depth check passed." shell: bash - build-gha-x86: + gha-x86: runs-on: ubuntu-latest needs: smoke-tests strategy: @@ -70,30 +70,23 @@ jobs: name: Checkout code uses: actions/checkout@v4.1.1 - - name: Build and test FTL + name: Build and test and deploy FTL uses: ./.github/actions/build-and-test with: platform: ${{ matrix.platform }} bin_name: ${{ matrix.bin_name }} artifact_name: ${{ matrix.bin_name }}-binary + target_dir: ${{ needs.smoke-tests.outputs.OUTPUT_DIR }} git_branch: ${{ needs.smoke-tests.outputs.GIT_BRANCH }} git_tag: ${{ needs.smoke-tests.outputs.GIT_TAG }} event_name: ${{ github.event_name }} - - - name: Deploy - if: github.event_name != 'pull_request' - uses: ./.github/actions/deploy - with: - pattern: ${{ matrix.bin_name }}-binary - target_dir: ${{ needs.smoke-tests.outputs.OUTPUT_DIR }} - event_name: ${{ github.event_name }} actor: ${{ github.actor }} SSH_KEY: ${{ secrets.SSH_KEY }} KNOWN_HOSTS: ${{ secrets.KNOWN_HOSTS }} SSH_USER: ${{ secrets.SSH_USER }} SSH_HOST: ${{ secrets.SSH_HOST }} - build-gha-riscv64: + gha-riscv64: runs-on: ubuntu-latest needs: smoke-tests env: @@ -105,30 +98,23 @@ jobs: name: Checkout code uses: actions/checkout@v4.1.1 - - name: Build and test FTL + name: Build and test and deploy FTL uses: ./.github/actions/build-and-test with: platform: linux/riscv64 bin_name: pihole-FTL-riscv64 artifact_name: pihole-FTL-riscv64-binary + target_dir: ${{ needs.smoke-tests.outputs.OUTPUT_DIR }} git_branch: ${{ needs.smoke-tests.outputs.GIT_BRANCH }} git_tag: ${{ needs.smoke-tests.outputs.GIT_TAG }} event_name: ${{ github.event_name }} - - - name: Deploy - if: github.event_name != 'pull_request' - uses: ./.github/actions/deploy - with: - pattern: ${{ matrix.bin_name }}-binary - target_dir: ${{ needs.smoke-tests.outputs.OUTPUT_DIR }} - event_name: ${{ github.event_name }} actor: ${{ github.actor }} SSH_KEY: ${{ secrets.SSH_KEY }} KNOWN_HOSTS: ${{ secrets.KNOWN_HOSTS }} SSH_USER: ${{ secrets.SSH_USER }} SSH_HOST: ${{ secrets.SSH_HOST }} - build-self-hosted: + self-hosted: runs-on: self-hosted needs: smoke-tests strategy: @@ -150,23 +136,16 @@ jobs: name: Checkout code uses: actions/checkout@v4.1.1 - - name: Build and test FTL + name: Build and test and deploy FTL uses: ./.github/actions/build-and-test with: platform: ${{ matrix.platform }} bin_name: ${{ matrix.bin_name }} artifact_name: ${{ matrix.bin_name }}-binary + target_dir: ${{ needs.smoke-tests.outputs.OUTPUT_DIR }} git_branch: ${{ needs.smoke-tests.outputs.GIT_BRANCH }} git_tag: ${{ needs.smoke-tests.outputs.GIT_TAG }} event_name: ${{ github.event_name }} - - - name: Deploy - if: github.event_name != 'pull_request' - uses: ./.github/actions/deploy - with: - pattern: ${{ matrix.bin_name }}-binary - target_dir: ${{ needs.smoke-tests.outputs.OUTPUT_DIR }} - event_name: ${{ github.event_name }} actor: ${{ github.actor }} SSH_KEY: ${{ secrets.SSH_KEY }} KNOWN_HOSTS: ${{ secrets.KNOWN_HOSTS }}