-
Notifications
You must be signed in to change notification settings - Fork 6
61 lines (61 loc) · 2.9 KB
/
issue-ops-deploy-to-cloud.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
on:
issue_comment:
types: [created]
name: React on issue comments
jobs:
react-on-issue-comment-not-approved:
runs-on: ubuntu-latest
if: startsWith(github.event.issue.title, 'Deploy Octocat Generator on') && startsWith(github.event.comment.body, '/approve') && github.event.issue.user.login == github.event.comment.user.login
steps:
- name: Need approval from somebody else
uses: actions/[email protected]
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '👋 @' + context.actor + ', you cannot approve your own deployment, somebody else has to add an ```/approve``` comment.'
})
react-on-issue-comment-approved:
runs-on: ubuntu-latest
if: startsWith(github.event.issue.title, 'Deploy Octocat Generator on') && startsWith(github.event.comment.body, '/approve') && github.event.issue.user.login != github.event.comment.user.login
steps:
- name: Approval granted
uses: actions/[email protected]
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '👋 @' + context.actor + ', approval granted, creating deployment request ...'
})
- name: Kicking off deployment
uses: actions/[email protected]
env:
title: ${{ github.event.issue.title }}
body: ${{ github.event.issue.body }}
with:
github-token: ${{secrets.GPR_PAT}}
script: |
const { title, body } = process.env;
let cloud = title.match(/^Deploy Octocat Generator on (.*)/)[1]
let customer = body.match(/^Customer: (.*)/)[1]
let customerNormalized = customer.replace(/[^a-zA-Z0-9_\-]*/g, '')
let gprUrl='docker.pkg.github.com/'+context.repo.owner.toLowerCase()+'/'+context.repo.repo.toLowerCase()+'/octocat-generator-docker:'+customerNormalized
github.repos.createDeployment({
owner: context.repo.owner,
repo: context.repo.repo,
ref: customerNormalized,
task: 'deploy-to-' + cloud,
auto_merge: false,
required_contexts: [],
environment: cloud + '-' + customerNormalized + '-' + context.issue.number,
description: 'Production environment for ' + customer + ' on ' + cloud,
payload: { customer: customer, cloud: cloud, gprUrl: gprUrl, issue: context.issue.number, customerNormalized: customerNormalized },
production_environment: false,
transient_environment: false
})