-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
79 lines (71 loc) · 3.05 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
name: "Create GitHub self hosted runner"
description: "Create a GitHub self hosted runner on Azure"
inputs:
client_id:
description: "Azure service principal App Id"
required: true
tenant_id:
description: "Azure tenant id"
required: true
subscription_id:
description: "Azure subscription Id"
required: true
container_app_environment_name:
description: "Azure container app environment name"
required: true
resource_group_name:
description: "Azure container app environment resource group name"
required: true
pat_token:
description: "GitHub PAT token to access to APIs to manage self hosted runner"
required: true
self_hosted_runner_image_tag:
description: "Self hosted runner image tag from https://github.com/pagopa/github-self-hosted-runner-azure/pkgs/container/github-self-hosted-runner-azure"
required: true
default: "v1.4.2@sha256:330b40e255e12c798f4a6e784efc3189e12316499dd399a3e3e6487c9b32f824"
outputs:
runner_name:
value: ${{ steps.create_github_runner.outputs.AZURE_CONTAINER_APP_NAME }}
description: "Azure Container App Name"
runs:
using: "composite"
steps:
- name: Login
id: login
uses: azure/login@v1
with:
client-id: ${{ inputs.client_id }}
tenant-id: ${{ inputs.tenant_id }}
subscription-id: ${{ inputs.subscription_id }}
- name: Create GitHub Runner
id: create_github_runner
shell: bash
run: |
### 0) Configure runner names and ids
TIMESTAMP=$(date +%s)
SELF_HOSTED_RUNNER_IMAGE="ghcr.io/pagopa/github-self-hosted-runner-azure:${{ inputs.self_hosted_runner_image_tag }}"
AZURE_RESOURCE_GROUP_NAME="${{ inputs.resource_group_name }}"
AZURE_CONTAINER_APP_ENVIRONMENT_NAME="${{ inputs.container_app_environment_name }}"
AZURE_CONTAINER_APP_NAME="runner-${{ github.run_id }}${TIMESTAMP}"
echo "[INFO] AZURE_CONTAINER_APP_NAME: ${AZURE_CONTAINER_APP_NAME}"
echo "::set-output name=AZURE_CONTAINER_APP_NAME::${AZURE_CONTAINER_APP_NAME}"
### 1) Register runner into current GitHub Repository
GITHUB_TOKEN=$(curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ inputs.pat_token }}" \
https://api.github.com/repos/${{ github.repository }}/actions/runners/registration-token | jq ".token" -re)
### 2) Create container app linked to created runner
az config set extension.use_dynamic_install=yes_without_prompt
az containerapp create \
--name "${AZURE_CONTAINER_APP_NAME}" \
--resource-group "${AZURE_RESOURCE_GROUP_NAME}" \
--image "${SELF_HOSTED_RUNNER_IMAGE}" \
--min-replicas 1 \
--max-replicas 1 \
--environment "${AZURE_CONTAINER_APP_ENVIRONMENT_NAME}" \
--secrets github-token="${GITHUB_TOKEN}" \
--env-vars \
LABELS="${AZURE_CONTAINER_APP_NAME}" \
GITHUB_REPOSITORY="https://github.com/${{ github.repository }}" \
GITHUB_TOKEN=secretref:github-token