Skip to content

Commit

Permalink
Merge pull request #218 from daltonv/dv_add_labels
Browse files Browse the repository at this point in the history
Resolve #217 - Update runner labels when needed
  • Loading branch information
MonolithProjects authored Sep 25, 2024
2 parents 68d961c + 1478aef commit fe97ec3
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 4 deletions.
23 changes: 23 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,26 @@
roles:
- robertdebock.epel
- monolithprojects.github_actions_runner

# Run the playbook again with different labels to test
- name: Dev test playbook second run
user: ansible
hosts: all
gather_facts: yes
become: yes
vars:
runner_user: ansible
github_repo: "{{ lookup('env', 'GITHUB_REPO') }}"
github_account: "{{ lookup('env', 'GITHUB_ACCOUNT') }}"
runner_version: "latest"
runner_name: test_name
runner_on_ghes: yes
reinstall_runner: false
hide_sensitive_logs: no
runner_labels:
- label1
- repo-runner
- label2
roles:
- robertdebock.epel
- monolithprojects.github_actions_runner
4 changes: 2 additions & 2 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@

- name: Check Labels (skipped if labels are OK)
ansible.builtin.fail:
msg: Woops some labels differ "{{ (registered_runners.json.runners.0 | json_query('labels[*].name') | difference(['self-hosted', 'Linux', 'X64', 'label1', 'repo-runner'])) }}"
when: not (registered_runners.json.runners.0 | json_query('labels[*].name') | list ) == (['self-hosted', 'Linux', 'X64', 'label1', 'repo-runner'] | list)
msg: Woops some labels differ "{{ (registered_runners.json.runners.0 | json_query('labels[*].name') | difference(['self-hosted', 'Linux', 'X64', 'label1', 'repo-runner', 'label2'])) }}"
when: not (registered_runners.json.runners.0 | json_query('labels[*].name') | list ) == (['self-hosted', 'Linux', 'X64', 'label1', 'repo-runner', 'label2'] | list)
19 changes: 19 additions & 0 deletions molecule/repo/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,22 @@
roles:
- robertdebock.epel
- monolithprojects.github_actions_runner

# Run the playbook again with different labels to test
- name: Update Repo runner
user: ansible
hosts: all
gather_facts: yes
become: yes
vars:
runner_user: ansible
github_repo: "{{ lookup('env', 'GITHUB_REPO') }}"
github_account: "{{ lookup('env', 'GITHUB_ACCOUNT') }}"
runner_version: "latest"
runner_labels:
- label1
- repo-runner
- label2
roles:
- robertdebock.epel
- monolithprojects.github_actions_runner
4 changes: 2 additions & 2 deletions molecule/repo/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@

- name: Check Labels (skipped if labels are OK)
ansible.builtin.fail:
msg: Woops some labels differ "{{ (registered_runners.json.runners.0 | json_query('labels[*].name') | difference(['self-hosted', 'Linux', 'X64', 'label1', 'repo-runner'])) }}"
when: not (registered_runners.json.runners.0 | json_query('labels[*].name') | list ) == (['self-hosted', 'Linux', 'X64', 'label1', 'repo-runner'] | list)
msg: Woops some labels differ "{{ (registered_runners.json.runners.0 | json_query('labels[*].name') | difference(['self-hosted', 'Linux', 'X64', 'label1', 'repo-runner', 'label2'])) }}"
when: not (registered_runners.json.runners.0 | json_query('labels[*].name') | list ) == (['self-hosted', 'Linux', 'X64', 'label1', 'repo-runner', 'label2'] | list)
19 changes: 19 additions & 0 deletions tasks/install_runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@
no_log: "{{ hide_sensitive_logs | bool }}"
when: runner_name not in registered_runners.json.runners|map(attribute='name')|list

- name: Update runner labels if changed
ansible.builtin.uri:
url: "{{ github_full_api_url }}/{{ (registered_runners.json.runners | selectattr('name', 'equalto', runner_name) | first).id }}/labels"
headers:
Authorization: "Bearer {{ access_token }}"
Accept: "application/vnd.github+json"
method: PUT
body_format: json
body:
labels: "{{ runner_labels }}"
status_code: 200
force_basic_auth: true
when:
- runner_name in registered_runners.json.runners|map(attribute='name')|list
- (runner_labels | sort) != (registered_runners.json.runners | selectattr('name', 'equalto', runner_name) | first).labels |
selectattr('type', 'equalto', 'custom') |
map(attribute='name') |
list

- name: Replace registered runner # noqa no-changed-when
environment:
RUNNER_ALLOW_RUNASROOT: "1"
Expand Down

0 comments on commit fe97ec3

Please sign in to comment.