Skip to content

Commit

Permalink
ci: add github actions workflow to test self hosted runner
Browse files Browse the repository at this point in the history
  • Loading branch information
anjannath committed Oct 22, 2024
1 parent 8d5f496 commit bd6c662
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-oci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: oci-builds
on:
push:
branches: [ main ]
tags:
tags:
- '*'
pull_request:
branches: [ main ]
Expand All @@ -21,7 +21,7 @@ jobs:
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 }}
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
- name: Save image for PR
Expand All @@ -47,4 +47,4 @@ jobs:
if: ${{ github.event_name != 'pull_request' }}
shell: bash
run: make oci-push

55 changes: 55 additions & 0 deletions .github/workflows/build-on-hosted-runner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: build-on-hosted-runner

on:
pull_request:
push:
branches:
- "main"
- "*"
jobs:
get_runner_registration_token:
runs-on: ubuntu-24.04
outputs:
runner_reg_token: ${{steps.fetch_token.output.token}}
steps:
- name: fetch token from API
id: fetch_token
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{secrets.GH_PAT_TOKEN}}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/redhat-developer/mapt/actions/runners/registration-token > token
token=$(cat token | jq .token)
echo "::add-mask::$token"
echo "token=$token" >> "$GITHUB_OUTPUT"
hosted_runner_provision:
needs: get_runner_registration_token
uses: ./provision-hosted-runner.yaml
with:
runner_repo: 'https://github.com/redhat-developer/mapt'
operating_system: ubuntu
runner_registration_token: ${{needs.get_runner_registration_token.outputs.runner_reg_token}}
secrets: inherit

test_run_selfhosted_runner:
runs-on: az-runner-ubuntu-${{github.even.workflow_run.id}}
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 ./...

destroy_hosted_runner:
uses: ./destroy-hosted-runner.yaml
with:
operating_system: ubuntu
31 changes: 31 additions & 0 deletions .github/workflows/destroy-hosted-runner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: destroy-hosted-runner

on:
workflow_call:
inputs:
operating_system:
required: true
type: string

jobs:
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}}
export AZURE_SOTRAGE_ACCOUNT=${{secrets.AZURE_SOTRAGE_ACCOUNT}}
export AZURE_STORAGE_KEY=${{secrets.AZURE_STORAGE_KEY}}
./out/mapt azure ${{inputs.operating_system}} destroy --project-name "az-ghrunner" \
--backed-url "azblob://mapt-gh-runner-mapt-state/${{github.repository}}-${{github.event.workflow_run.id}}"
44 changes: 44 additions & 0 deletions .github/workflows/provision-hosted-runner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: provision-hosted-runner

on:
workflow_call:
inputs:
operating_system:
required: true
type: string
runner_repo:
required: true
type: string
runner_registration_token:
required: true
type: string

jobs:
provision_runner:
name: provision-runner
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: 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}}
export AZURE_SOTRAGE_ACCOUNT=${{secrets.AZURE_SOTRAGE_ACCOUNT}}
export AZURE_STORAGE_KEY=${{secrets.AZURE_STORAGE_KEY}}
mkdir $HOME/workspace
./out/mapt azure ${{inputs.operating_system}} create --spot --project-name "az-ghrunner" \
--backed-url "azblob://mapt-gh-runner-mapt-state/${{github.repository}}-${{github.event.workflow_run.id}}" \
--install-ghactions-runner --ghactions-runner-name "az-runner-${{inputs.operating_system}}-${{github.event.workflow_run.id}}" \
--ghactions-runner-repo "${{inputs.runner_repo}}" --ghactions-runner-token ${{inputs.runner_registration_token}}

0 comments on commit bd6c662

Please sign in to comment.