From 36fb8c46dc2ffe65b0fface74b5b9e263deec117 Mon Sep 17 00:00:00 2001 From: Anjan Nath Date: Thu, 29 Aug 2024 15:49:18 +0530 Subject: [PATCH] ci: add github actions workflow to test self hosted runner --- .github/workflows/build-oci.yaml | 47 ++++++++-------- .github/workflows/hosted-runner.yaml | 83 ++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/hosted-runner.yaml diff --git a/.github/workflows/build-oci.yaml b/.github/workflows/build-oci.yaml index f3b0b2487..38ce8e646 100644 --- a/.github/workflows/build-oci.yaml +++ b/.github/workflows/build-oci.yaml @@ -1,6 +1,7 @@ name: oci-builds on: + workflow_call: push: branches: [ main ] tags: @@ -17,34 +18,32 @@ jobs: uses: actions/checkout@v4 - name: Build image for PR - if: ${{ github.event_name == 'pull_request' }} shell: bash run: | - IMG=ghcr.io/redhat-developer/mapt:pr-${{ github.event.number }} make oci-build - podman save -o mapt.tar ghcr.io/redhat-developer/mapt:pr-${{ github.event.number }} - echo "ghcr.io/redhat-developer/mapt:pr-${{ github.event.number }}" > mapt-image + IMG=ghcr.io/redhat-developer/mapt:pr make oci-build + podman save -o mapt.tar ghcr.io/redhat-developer/mapt:pr - name: Save image for PR uses: actions/upload-artifact@v4 with: - name: mapt - path: mapt* + name: mapt-pr + path: mapt.tar - - name: Build image - if: ${{ github.event_name != 'pull_request' }} - shell: bash - run: make oci-build - - - name: Log in to quay.io Registry - if: ${{ github.event_name != 'pull_request' }} - uses: redhat-actions/podman-login@v1 - with: - registry: quay.io - username: ${{ secrets.QUAY_IO_USERNAME }} - password: ${{ secrets.QUAY_IO_PASSWORD }} - - - name: Push image - if: ${{ github.event_name != 'pull_request' }} - shell: bash - run: make oci-push - + # - name: Build image + # if: ${{ github.event_name != 'pull_request' }} + # shell: bash + # run: make oci-build + # + # - name: Log in to quay.io Registry + # if: ${{ github.event_name != 'pull_request' }} + # uses: redhat-actions/podman-login@v1 + # with: + # registry: quay.io + # username: ${{ secrets.QUAY_IO_USERNAME }} + # password: ${{ secrets.QUAY_IO_PASSWORD }} + # + # - name: Push image + # if: ${{ github.event_name != 'pull_request' }} + # shell: bash + # run: make oci-push + # diff --git a/.github/workflows/hosted-runner.yaml b/.github/workflows/hosted-runner.yaml new file mode 100644 index 000000000..0012117b6 --- /dev/null +++ b/.github/workflows/hosted-runner.yaml @@ -0,0 +1,83 @@ +name: hosted-runner + +on: + pull_request: {} + push: + branches: + - main + - '*' + +jobs: + call-oci-build: + uses: ./.github/workflows/build-oci.yaml + provision_runner: + needs: call-oci-build + name: provision-runner + runs-on: ubuntu-24.04 + steps: + - name: Download oci-builds artifact + uses: actions/download-artifact@v4 + with: + name: mapt-pr + run-id: ${{ github.event.workflow_run.id }} + github-token: ${{ github.token }} + - name: Import downloaded mapt image + run: podman load -i mapt.tar + - name: Podman images + run: podman images + # - name: Code checkout + # uses: actions/checkout@v4 + # - name: Set up Go + # uses: actions/setup-go@v5 + # with: + # go-version: '1.21' + # - name: Build + # run: make build + # - name: Test + # run: go test -v ./... + # - name: Run mapt + # run: | + # export ARM_CLIENT_ID=${{ secrets.arm_client_id }} + # export ARM_CLIENT_SECRET=${{ secrets.arm_client_secret }} + # export ARM_TENANT_ID=${{ secrets.arm_tenant_id }} + # export ARM_SUBSCRIPTION_ID=${{ secrets.arm_subscription_id }} + # mkdir $HOME/workspace + # ./out/mapt create azure ${{ inputs.operating_system }} create --spot --project-name "az-ghrunner" \ + # --backed-url "file://$HOME/workspace" --install-ghactions-runner --ghactions-runner-name "az-runner-${{ inputs.operating_system }}" \ + # --ghactions-runner-repo ${{ inputs.repository }} --ghactions-runner-token ${{ secrets.runner_registration_token }} + + # test_run_selfhosted_runner: + # runs-on: az-runner-${{ inputs.operating_system }} + # needs: provision_runner + # steps: + # - name: Code checkout + # uses: actions/checkout@v4 + # - name: Set up Go + # uses: actions/setup-go@v5 + # with: + # go-version: '1.21' + # - name: Build + # run: make build + # - name: Test + # run: go test -v ./... + # + # remove_cloud_instance: + # runs-on: ubuntu-24.04 + # steps: + # - name: Code checkout + # uses: actions/checkout@v4 + # - name: Set up Go + # uses: actions/setup-go@v5 + # with: + # go-version: '1.21' + # - name: Build + # run: make build + # - name: Destroy instance + # run: | + # export ARM_CLIENT_ID=${{ secrets.arm_client_id }} + # export ARM_CLIENT_SECRET=${{ secrets.arm_client_secret }} + # export ARM_TENANT_ID=${{ secrets.arm_tenant_id }} + # export ARM_SUBSCRIPTION_ID=${{ secrets.arm_subscription_id }} + # ./out/mapt create azure ${{ inputs.operating_system }} destroy --project-name "az-ghrunner" \ + # --backed-url "file://$HOME/workspace" + #