-
Notifications
You must be signed in to change notification settings - Fork 22
43 lines (41 loc) · 1.38 KB
/
cd.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
name: CD
on:
push:
branches:
- 'cd/prod'
jobs:
pull-request:
name: Open PR to main
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Create Pull Request
uses: actions/github-script@v6
with:
script: |
const head = process.env.GITHUB_REF_NAME;
const env = head.replace(/cd\//g, '');
core.info(`Checking branch '${head}' for automated deployment to '${env}' environment...`);
const { repo, owner } = context.repo;
try {
const result = await github.rest.pulls.create({
title: `Deploy latest to \`${env}\` environment`,
owner,
repo,
head,
base: 'main',
body: `Approve changes and merge this PR to trigger deployment to \`${env}\` environment.`
});
await github.rest.issues.addLabels({
owner,
repo,
issue_number: result.data.number,
labels: ['cd', `env:${env}`]
});
} catch (e) {
if (!e.message.includes('A pull request already exists') && !e.message.includes('No commits between')) {
throw e
}
core.info(`Skipped PR creation: ${e.message}`)
}