Skip to content

Commit

Permalink
Add gh_deploy tag to github deploy tasks so they can easily be skipped
Browse files Browse the repository at this point in the history
related to #45
  • Loading branch information
rlskoeser committed Nov 14, 2023
1 parent 3c46ab0 commit 4846699
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
30 changes: 16 additions & 14 deletions roles/close_deployment/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
# Closes a successful GitHub deployment, depends on deployment variable
# registered by create_deployment task
###
- block:
- name: Close GitHub deployment as a success.
uri:
url: '{{ deployment.json.url }}/statuses'
body_format: json
method: POST
status_code: 201
body:
state: "success"
description: "Deployment succeeded"
headers:
Authorization: "token {{ github_token }}"
when: deploy_environment != "staging"
# no rescue because if this fails, closing an errored deploy will too!

- name: Close GitHub deployment as a success.
tags:
- gh_deploy
uri:
url: "{{ deployment.json.url }}/statuses"
body_format: json
method: POST
status_code: 201
body:
state: "success"
description: "Deployment succeeded"
headers:
Authorization: "token {{ github_token }}"
when: deploy_environment != "staging"
# no rescue because if this fails, closing an errored deploy will too!
16 changes: 9 additions & 7 deletions roles/create_deployment/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,32 @@
# a success.
###
- name: Create a GitHub deployment
tags:
- gh_deploy
block:
- name: Check for GitHub token, and fail if not present
fail:
msg: "Pass a GitHub API token to -e github_token or set in environment as ANSIBLE_GITHUB_TOKEN"
msg: "Pass a GitHub API token to -e github_token or set in environment as ANSIBLE_GITHUB_TOKEN"
when: github_token == ""
- name: Create a deployment
uri:
url: '{{ deployments_endpoint }}'
url: "{{ deployments_endpoint }}"
body_format: json
method: POST
status_code: 201
body:
ref: '{{ gitref }}'
environment: '{{ deploy_environment }}'
description: '{{ deploy_description }}'
required_contexts: '{{ deploy_contexts }}'
ref: "{{ gitref }}"
environment: "{{ deploy_environment }}"
description: "{{ deploy_description }}"
required_contexts: "{{ deploy_contexts }}"
auto_merge: false
headers:
Authorization: "token {{ github_token }}"
return_content: true
register: deployment
- name: Set status to in progress
uri:
url: '{{ deployment.json.url }}/statuses'
url: "{{ deployment.json.url }}/statuses"
body_format: json
method: POST
status_code: 201
Expand Down

0 comments on commit 4846699

Please sign in to comment.