-
Notifications
You must be signed in to change notification settings - Fork 20
149 lines (125 loc) · 5.19 KB
/
publish-rc.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: Release RC
on:
push:
branches:
- dev
jobs:
state:
if: ${{ github.actor == 'github-merge-queue[bot]' }}
name: State
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
outputs:
HAS_ASSETS: ${{ steps.scope.outputs.result }}
PR: ${{ steps.pull_request.outputs.result }}
steps:
## Получаем актуальное состояние dev branch
- name: Checkout
uses: actions/checkout@v4
with:
show-progress: false
fetch-depth: 0
- name: Prepare environment
uses: ./.github/actions/prepare-environment
## Получаем информацию о pull request который был влит
## context.sha - это последний commit в dev ветку
## base.sha - это последний commit base branch до влития целевого pull request
- name: Get associated pull request by commit
id: pull_request
uses: actions/github-script@v6
with:
script: |
const teammate = {
Yakutoc: "alex_czech",
'neretin-trike': "aaneretin",
'Yeti-or': "yeti-or",
TitanKuzmich: "aakrivonos",
kayman233: "ivakudryavtsev",
shuga2704: "shuga2704",
};
const res = await github.rest.repos.listPullRequestsAssociatedWithCommit({
commit_sha: context.sha,
owner: context.repo.owner,
repo: context.repo.repo,
});
const {
base: { sha = context.sha },
title,
user: { login }
} = res?.data[0] || {};
return { sha, pr: title, user: teammate[login] || 'alex_czech' };
## Сохраняем вывод команды lerna ls в формате json array
- name: Preserve lerna ls state
id: lerna_ls
env:
SHA: ${{ fromJSON(steps.pull_request.outputs.result).sha }}
run: |
echo "RAW_DATA=$(npx lerna la --json --since=${{ env.SHA }} | jq -c)" >> "$GITHUB_OUTPUT"
## Высчитываем условие для загрузки assets
- name: Computed scope state
id: scope
uses: actions/github-script@v6
env:
RAW_DATA: ${{ steps.lerna_ls.outputs.RAW_DATA }}
with:
script: |
const processingScope = require('./.github/processing-scope.js');
const state = processingScope();
return state.HAS_ASSETS ?? false;
publish:
name: Publish RC version
needs: [ state ]
if: ${{ github.actor == 'github-merge-queue[bot]' }}
uses: ./.github/workflows/publish-common.yml
with:
with-update-package-lock: true
commit-message: "Update package-lock.json files"
upload_assets: ${{ needs.state.outputs.HAS_ASSETS == 'true' }}
auto-options: '--no-changelog'
secrets:
gh_token: ${{ secrets.GH_TOKEN }}
npm_registry_token: ${{ secrets.NPM_REGISTRY_TOKEN }}
catch:
name: Handle errors
runs-on: ubuntu-latest
needs: [ state, publish ]
if: ${{ always() && contains(needs.*.result, 'failure') }}
env:
FAILED_JOB_NAME: ${{ contains(needs.change-state.result, 'failure') && 'State' || 'Publish RC version / publish' }}
steps:
- name: Get failed job information
id: job
uses: actions/github-script@v6
env:
RUN_ID: ${{github.run_id}}
FAILED_JOB_NAME: ${{ env.FAILED_JOB_NAME }}
with:
script: |
const { RUN_ID, FAILED_JOB_NAME } = process.env;
const res = await github.rest.actions.listJobsForWorkflowRun({
run_id: RUN_ID,
owner: context.repo.owner,
repo: context.repo.repo,
});
const { data: { jobs: jobsList } } = res;
const { html_url, steps: stepsList } = jobsList.find(({ name }) => name === FAILED_JOB_NAME ) || {};
const { name } = stepsList.find(({ conclusion }) => conclusion === "failure" ) || { name: '' };
return { job: html_url, name }
- name: Create message
env:
PR: ${{ fromJSON(needs.state.outputs.PR).pr }}
USER: ${{ fromJSON(needs.state.outputs.PR).user }}
FAILURE_STEP: ${{ fromJSON(steps.job.outputs.result).name }}
JOB: ${{ fromJSON(steps.job.outputs.result).job }}
run: |
step="**Failure step**: ${{ env.FAILURE_STEP }}"
message='@${{ env.USER }}\nПосмотри пожалуйста, упала публикация твоего pull request: [${{ env.PR }}](${{ env.JOB }})'
echo "NOTIFICATION="$step\\n\\n$message"" >> $GITHUB_ENV
- name: Create the Mattermost Message
run: |
echo "{\"text\":\" ${{ env.NOTIFICATION }}\"}" > mattermost.json
- name: Send notification
uses: mattermost/action-mattermost-notify@master
env:
MATTERMOST_WEBHOOK_URL: ${{ secrets.WEBHOOKS_NOTIFICATIONS_MM }}