forked from lgvorg1/cicd_top10_3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.yml.new.txt
151 lines (127 loc) · 4.87 KB
/
deploy.yml.new.txt
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
148
149
150
151
name: Test CI
on:
workflow_run:
workflows: [ 'Build CI' ]
types: [completed]
env:
MY_SECRET: ${{ secrets.MY_SECRET }}
GITHUB_PAT: ${{ secrets.GH_PAT }}
jobs:
deploy:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Alive
run: |
echo "I am alive"
# By default, checks out base code (not PR code)
- name: Checkout repository
uses: actions/checkout@v4
#- name: Echoing runtests.sh
# run: |
# echo "My run id : ${{ github.event.workflow_run.workflow_id }}"
# ls -lR
# echo echoing runtests.sh ....
# cat runtests.sh
#- name: download pr atifact
# uses: dawidd6/action-download-artifact@v2
# with:
# workflow: ${{ github.event.workflow_run.workflow_id }}
# path: ./
#name: archive-dist
#path: path/to/artifact_david
- name: Echoing runtests.sh after downloading artifact
run: |
ls -lR
echo cat runtests.sh
cat runtests.sh
#- uses: actions/download-artifact@v3
# with:
# name: archive-dist
# path: path/to/artifact
#- name: Display structure of downloaded files
# run: ls -R
# working-directory: path/to/artifact
- name: 'Download artifact'
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 == "archive-bin"
})[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}/myartifact.zip`, Buffer.from(download.data));
- name: 'Unzip artifact'
run: |
unzip -o myartifact.zip
ls -lR
cat runtests.sh
# Runs tests
- name: Running tests ...
id : run_tests
run: |
echo Running tests..
chmod +x runtests.sh
cat runtests.sh
#./runtests.sh "${{ github.event.pull_request.user.login }}" "${{ github.workflow }}"
bash ./runtests.sh "${{ github.event.workflow_run.actor.name }}" "${{ github.workflow }}"
export ret_value=$?
echo ret_value $ret_value
cat runtests.out
echo Tests executed.
echo "run_tests=OK" >> $GITHUB_OUTPUT
#
# For demo purposes, the check merge condition will always be set to FALSE (avoiding to merge)
#
- name: pr_check_conditions_to_merge
id: check_pr
run: |
echo "check_conditions_to_merge"
PR_ID=$(<PR_ID.txt)
PR_TITLE=$(<PR_TITLE.txt)
echo "Checking conditions to merge PR with id $PR_ID and Title $PR_TITLE"
echo "Checking conditions to merge PR with id $PR_ID and Title $(<PR_TITLE.txt)"
echo "merge=false" >> $GITHUB_OUTPUT
- name: pr_merge_pr_false
if: steps.check_pr.outputs.merge == 'false'
run: |
echo "The merge check was ${{ steps.check_pr.outputs.merge }}"
echo "Merge conditions NOT MEET!!!"
- name: pr_merge_pr_true
if: steps.check_pr.outputs.merge == 'true' && steps.run_tests.outputs.run_tests == 'OK'
run: |
echo "The merge check was ${{ steps.check_pr.outputs.merge }}"
echo "Merge conditions successfully MEET!!!"
echo "Merging .."
PR_ID=$(<PR_ID.txt)
curl -L \
-X PUT \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_PAT" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/lgvorg1/"${{github.event.repository.name}}"/pulls/"$PR_ID"/merge \
-d '{"commit_title":"Expand enum","commit_message":"Add a new value to the merge_method enum"}'
#- name: 'Comment on PR'
# uses: actions/github-script@v6
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# script: |
# let fs = require('fs');
# let issue_number = Number(fs.readFileSync('./pr_number'));
# await github.rest.issues.createComment({
# owner: context.repo.owner,
# repo: context.repo.repo,
# issue_number: issue_number,
# body: 'Thank you for the PR!'
# });