-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ci: add github actions workflow to test self hosted runner #282
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: build-on-hosted-runner | ||
|
||
on: | ||
workflow_run: | ||
workflows: | ||
- oci-builds | ||
types: | ||
- completed | ||
|
||
jobs: | ||
hosted_runner_provision: | ||
if: | | ||
github.event.workflow_run.conclusion == 'success' && | ||
github.event.workflow_run.event == 'pull_request' | ||
uses: ./.github/workflows/provision-hosted-runner.yaml | ||
with: | ||
runner_repo: "https://github.com/${{github.repository}}" | ||
operating_system: windows | ||
secrets: inherit | ||
|
||
test_run_selfhosted_runner: | ||
runs-on: [self-hosted, x64, Windows] | ||
needs: hosted_runner_provision | ||
steps: | ||
- name: Code checkout | ||
uses: actions/checkout@v4 | ||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: "1.21" | ||
- name: Test | ||
run: go test -v ./... | ||
|
||
destroy_hosted_runner: | ||
needs: | ||
- test_run_selfhosted_runner | ||
- hosted_runner_provision | ||
if: always() && !contains(needs.*.result, 'skipped') && !contains(needs.*.result, 'cancelled') | ||
uses: ./.github/workflows/destroy-hosted-runner.yaml | ||
with: | ||
operating_system: windows | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
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: Download mapt image from artifacts | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: mapt | ||
run-id: ${{ github.event.workflow_run.id }} | ||
github-token: ${{ github.token }} | ||
- name: Import mapt image | ||
run: | | ||
podman load -i mapt.tar | ||
podman images | ||
- name: Destroy instance | ||
run: | | ||
MAPT_IMAGE=$(cat mapt-image) | ||
podman run --name mapt-destroy --rm \ | ||
-v ${PWD}:/workspace:z \ | ||
-e ARM_CLIENT_ID=${{secrets.ARM_CLIENT_ID}} \ | ||
-e ARM_CLIENT_SECRET=${{secrets.ARM_CLIENT_SECRET}} \ | ||
-e ARM_TENANT_ID=${{secrets.ARM_TENANT_ID}} \ | ||
-e ARM_SUBSCRIPTION_ID=${{secrets.ARM_SUBSCRIPTION_ID}} \ | ||
-e AZURE_STORAGE_ACCOUNT=${{secrets.AZURE_STORAGE_ACCOUNT}} \ | ||
-e AZURE_STORAGE_KEY=${{secrets.AZURE_STORAGE_KEY}} \ | ||
${MAPT_IMAGE} azure ${{inputs.operating_system}} \ | ||
destroy --project-name "az-ghrunner" \ | ||
--backed-url "azblob://mapt-gh-runner-mapt-state/${{ github.repository }}-${{ github.run_id }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
name: provision-hosted-runner | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
operating_system: | ||
required: true | ||
type: string | ||
runner_repo: | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
provision_runner: | ||
name: provision-runner | ||
runs-on: ubuntu-24.04 | ||
steps: | ||
- name: fetch token from API | ||
id: fetch_token | ||
run: | | ||
curl -s -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/${{github.repository}}/actions/runners/registration-token > token | ||
token=$(cat token | jq .token) | ||
echo "::add-mask::$token" | ||
echo "runner_token=$token" >> "$GITHUB_OUTPUT" | ||
|
||
- name: Download mapt image from artifacts | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: mapt | ||
run-id: ${{ github.event.workflow_run.id }} | ||
github-token: ${{ github.token }} | ||
|
||
- name: Import mapt image | ||
run: | | ||
podman load -i mapt.tar | ||
podman images | ||
|
||
- name: Run mapt | ||
run: | | ||
MAPT_IMAGE=$(cat mapt-image) | ||
podman run --name mapt-create --rm \ | ||
-v ${PWD}:/workspace:z \ | ||
-e ARM_CLIENT_ID=${{secrets.ARM_CLIENT_ID}} \ | ||
-e ARM_CLIENT_SECRET=${{secrets.ARM_CLIENT_SECRET}} \ | ||
-e ARM_TENANT_ID=${{secrets.ARM_TENANT_ID}} \ | ||
-e ARM_SUBSCRIPTION_ID=${{secrets.ARM_SUBSCRIPTION_ID}} \ | ||
-e AZURE_STORAGE_ACCOUNT=${{secrets.AZURE_STORAGE_ACCOUNT}} \ | ||
-e AZURE_STORAGE_KEY=${{secrets.AZURE_STORAGE_KEY}} \ | ||
${MAPT_IMAGE} azure ${{inputs.operating_system}} create \ | ||
--spot --project-name "az-ghrunner" --conn-details-output /workspace \ | ||
--backed-url "azblob://mapt-gh-runner-mapt-state/${{ github.repository }}-${{ github.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 ${{steps.fetch_token.outputs.runner_token}} | ||
|
||
- name: wait for runner to start accepting jobs | ||
run: sleep 120 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity why is this needed? I was expecting when it is ready the job
test_run_selfhosted_runner
will be executedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
during testing i found that when the job executed immediately the runner would never pick it up, couldn't figure out why this was happening
i just tried opening a second PR just to test by running a different workflow targeting that runner then it'd work and it'd also pickup the pending
test_run_selfhosted_runner
job, so figured that if there's a bit of delay between the runner getting added and the next job getting triggered it all works