-
Notifications
You must be signed in to change notification settings - Fork 44
119 lines (105 loc) · 4.15 KB
/
06-deployed.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
name: deployed feedback
on:
workflow_call:
inputs:
integrations:
required: true
type: string
jobs:
deployed:
name: feedback
runs-on: ubuntu-latest
steps:
- name: install depends for load scripts
run: |
npm install @octokit/[email protected]
npm install @octokit/[email protected]
npm install js-yaml
- name: Get token using github-script
id: get-token
uses: actions/github-script@v6
env:
APP_ID: ${{ secrets.APP_ID }}
APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}
with:
script: |
global["fetch"] = fetch
const { Octokit } = require("@octokit/rest");
const { createAppAuth } = require("@octokit/auth-app");
const appOctokit = new Octokit({
authStrategy: createAppAuth,
auth: {
appId: process.env.APP_ID,
privateKey: process.env.APP_PRIVATE_KEY,
}
});
const app_installation = await appOctokit.rest.apps.getRepoInstallation({
owner: context.payload.organization.login,
repo: context.payload.repository.name
});
const { token } = await appOctokit.auth({
type: "installation",
installationId: app_installation.data.id
});
core.setOutput('app_token', token)
- name: update records
uses: actions/github-script@v6
with:
github-token: ${{ steps.get-token.outputs.app_token }}
script: |
const yaml = require('js-yaml');
const newIntergrated = ${{ inputs.integrations }}
const {data} = await github.rest.repos.getContent({
owner: context.repo.owner,
repo: context.repo.repo,
path: "records.yml",
});
datas = Buffer.from(data.content, data.encoding)
recordsContent = yaml.load(datas.toString())
if ( recordsContent.records === null || recordsContent.records === undefined ) {
recordsContent.records = {}
}
newIntergrated.forEach(repo => {
recordsContent.records[repo.repo] = {"ver": repo.tag, "date": new Date().toISOString().split('T')[0], "pr": ${{ github.event.number }}}
})
const contentString = yaml.dump(recordsContent, {'sortKeys': true ,indent: 4})
let contentBinary = Buffer.from(contentString).toString("base64")
await github.rest.repos.createOrUpdateFileContents({
owner: context.repo.owner,
repo: context.repo.repo,
sha: data.sha,
path: "records.yml",
message: "update records from https://github.com/${{ github.repository }}/pull/${{ github.event.number }}",
content: contentBinary,
branch: "master",
})
- name: label intergerted
uses: actions/github-script@v6
with:
github-token: ${{ github.token }}
script: |
const { data } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const labeled = (data.find(label => label.name === "Merged") !== undefined)
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['Merged']
})
- name: close this pull request
shell: python
env:
GITHUB_TOKEN: ${{ steps.get-token.outputs.app_token }}
run: |
import requests
import os
headers = {
"Accept": "application/vnd.github+json",
"Authorization":"Bearer " + os.environ.get("GITHUB_TOKEN")
}
res = requests.patch(url="https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.number }}",
headers=headers, json= {'state': 'closed'})