DEV Community

Cover image for I connected GitHub to Semaphore UI — and instantly fixed my dev workflow
Denis Gukov for Semaphore UI

Posted on

I connected GitHub to Semaphore UI — and instantly fixed my dev workflow

For one of my customers, I use Semaphore UI to build and deploy a WordPress website.
The pipeline is simple: Build → Automatic deploy to DEV → Manual deploy to PROD.

The website code and the Ansible playbooks live in separate repositories, so I use a small Ansible task to clone the website repository:

- name: Update repo from {{ website_branch_prepared }}
  ansible.builtin.git:
    repo: git@github.com:*****/{{ slug }}.git
    force: true
    accept_hostkey: true
    version: "{{ website_branch_prepared }}"
    dest: "{{ tmp_dir.path }}"
    key_file: "{{ tmp_key_file.path }}"
  register: git_info
Enter fullscreen mode Exit fullscreen mode

Since the source code is stored on GitHub, I use a GitHub webhook to trigger the Build task automatically on every commit.

GitHub webhook

The GitHub webhook calls the Semaphore Integration. Semaphore supports HMAC-based GitHub webhook authentication, so the setup is straightforward.

Semaphore Integration

Everything worked well except for one issue:
I needed Semaphore to build the same branch that I pushed to, without manually updating the template configuration each time.

GitHub webhooks include the branch name in the ref field, but in this format:

refs/heads/<branch_name>
Enter fullscreen mode Exit fullscreen mode

Semaphore Integrations can extract this field into a variable, but they do not modify or clean up the value.
To solve this, I added a simple Ansible task that prepares the branch name:

- name: Remove 'refs/heads/' prefix from branch name
  ansible.builtin.set_fact:
    website_branch_prepared: "{{ website_branch | regex_replace('^refs/heads/', '') }}"
Enter fullscreen mode Exit fullscreen mode

Semaphore value extractor

And that's it — now everything works exactly as I need!

Result

Top comments (0)