-
Notifications
You must be signed in to change notification settings - Fork 197
133 lines (123 loc) · 4.93 KB
/
cd_trigger.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
name: TeamsFx-CD Triggers
on:
workflow_run:
workflows: ["CD"]
branches: ["dev", "release/**"]
types: ["completed"]
jobs:
TeamsFxCICDTestMainTriggers:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' && startsWith(github.event.workflow_run.head_branch, 'release') }}
steps:
- name: Trigger TeamsFx-CICD-Test
run: |
curl \
-u :${{ secrets.GHEC_BOT_PAT }} \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/devdiv-azure-service-dmitryr/TeamsFx-CICD-Test/actions/workflows/trigger_cicd_by_main.yml/dispatches \
-d "{\"ref\":\"main\"}"
TeamsFxCICDTestDevTriggers:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'dev' }}
steps:
- name: Trigger TeamsFx-CICD-Test
run: |
curl \
-u :${{ secrets.GHEC_BOT_PAT }} \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/devdiv-azure-service-dmitryr/TeamsFx-CICD-Test/actions/workflows/trigger_cicd_by_dev.yml/dispatches \
-d "{\"ref\":\"main\"}"
DownloadAndOutput:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
outputs:
zipLink: ${{ steps.downloadUrl.outputs.result }}
pre_id: ${{ steps.preid.outputs.result }}
server_version: ${{ steps.version.outputs.result }}
stage: ${{ steps.series.outputs.result }}
steps:
- name: Download artifact
id: downloadUrl
uses: actions/github-script@v6
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "release"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/release.zip`, Buffer.from(download.data));
return matchArtifact.url
- name: Unzip artifact
run: unzip release.zip
- name: Get teamsfx-server version
id: version
uses: actions/github-script@v6
with:
script: |
let rawData = require('fs').readFileSync('./versions.json', {encoding:'utf8', flag:'r'});
let pkgs = JSON.parse(rawData);
let server = pkgs.find(item => item.name === "@microsoft/teamsfx-server")
console.log("==================", server.version)
return server.version
- name: Get stage input
id: series
uses: actions/github-script@v6
with:
script: |
let rawData = require('fs').readFileSync('./series.txt', {encoding:'utf8', flag:'r'});
if (rawData.trim() === "") rawData = "undefined"
console.log('-----------------', rawData)
return rawData;
- run: npm install semver
- name: Get teamsfx-server preid
id: preid
uses: actions/github-script@v6
with:
script: |
let rawData = require('fs').readFileSync('./versions.json', {encoding:'utf8', flag:'r'});
let pkgs = JSON.parse(rawData);
let server = pkgs.find(item => item.name === "@microsoft/teamsfx-server")
let semver = require('semver')
if(semver.prerelease(server.version)) {
console.log("===========", semver.prerelease(server.version)[0])
return semver.prerelease(server.version)[0]
} else {
console.log("=========== stable")
return "stable"
}
CheckSetupSuccess:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout branch
uses: actions/checkout@v3
with:
token: ${{ secrets.CD_PAT }}
ref: ${{ github.event.workflow_run.head_branch }}
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 14
- name: Setup project
id: setup
run: npm run setup
continue-on-error: true
- name: Info
if: steps.setup.outcome != 'success'
run: |
echo "`npm run setup` failed after current project finish CD,\
it may be the inconsistency of package dependencies caused by separate release,\
please confirm this problem will not affect the CI of subsequent PRs."