-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (143 loc) · 5.59 KB
/
ci_experiment.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
148
149
150
151
152
153
name: Manual experiment
on:
workflow_dispatch:
inputs:
pr_nr:
description: 'Pull request number'
required: true
type: number
default: 2
search_string:
description: 'Search title'
required: true
type: string
default: 'Update ci_coverage.yml'
environment:
description: 'Environment to run tests against'
type: environment
required: true
jobs:
manual_test:
runs-on: ubuntu-latest
steps:
- name: Blabla
id: get-pr-commits
uses: actions/github-script@v7
# env:
# FIRST_NAME: Mona
# LAST_NAME: Octocat
with:
# github-token: ${{ secrets.MY_PAT }}
# result-encoding: string
script: |
// const { FIRST_NAME, LAST_NAME } = process.env;
const owner = context.repo.owner; // same as: context.payload.repository.owner.login
const repo = context.repo.repo; // same as: context.payload.repository.name
const pull_number = context.payload.inputs.pr_nr;
// Get pull request
const pr_result = await github.rest.pulls.get({
owner,
repo,
pull_number,
});
const pr = {
author: pr_result.data.user,
title: pr_result.data.title,
body: pr_result.data.body.split(/\r?\n/),
};
console.log('PR:', pr);
console.log('');
// Get commits
const commits_result = await github.rest.pulls.listCommits({
owner,
repo,
pull_number,
});
// Extract author, title and body
const commits = commits_result.data.map(c => {
let msg = c.commit.message.split(/\r?\n/);
return {
author: c.author,
title: msg[0] || '',
body: msg.slice(2) || [],
};
});
console.log('Commits:', commits);
console.log('');
const r = {
pr,
commits,
all: [ pr ].concat(...commits),
};
console.log('return:', r);
console.log('');
return r;
# - name: Get result
# run: echo "${{ steps.get-pr-commits.outputs.result }}"
# NOTE!
# contains( array, string ) searches array for an EXACT match of string with one of its items
# contains( string1, string2 ) checks if string2 is SUBSTRING of string1
- name: Has commit with title '${{ github.event.inputs.search_string }}'
if: |
contains(
(fromJSON( steps.get-pr-commits.outputs.result )).commits.*.title,
github.event.inputs.search_string
)
run: echo TRUE
- name: Has title containing 'CI'
if: |
contains(
fromJSON( steps.get-pr-commits.outputs.result ).pr.title,
'CI'
)
run: echo TRUE
# # - name: Check out repository
# # uses: actions/checkout@v3
# # with:
# # token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
# # - name: Set Git user
# # run: |
# # git config --global user.name 'vHeemstra'
# # git config --global user.email '17368112+vHeemstra@users.noreply.github.com'
# - name: Get first 250 commits from PR
# # For each commit extracts object:
# # {
# # author: {
# # name: '',
# # email: '',
# # date: '2022-06-09T16:09:33Z'
# # },
# # message: {
# # title: '', // First line of message
# # body: [ ... ], // Third+ lines
# # }
# # }
# # See also:
# # https://docs.github.com/en/rest/pulls/pulls#list-commits-on-a-pull-request
# id: get_pr_commits
# env:
# PR_NR: ${{ github.event.inputs.pr_nr }}
# API_HEADER: 'Accept: application/vnd.github.v3+json'
# # Is: https://api.github.com/repos/vHeemstra/fill-pot-po/pulls{/number}
# API_PR_URL: ${{ github.event.repository.pulls_url }}
# # See: https://jqplay.org/s/6ooNjDtT9Ci or: https://jqplay.org/s/19HnH7PHwHa
# JQ_FILTER: '[ .[] | { author: .commit.author, message: ( .commit.message | split(\"\n\") | { title: .[0], body: ( .[2:] ) } ) } ] | @json'
# run: |
# # Authenticate GitHub CLI
# echo ${{ secrets.GITHUB_TOKEN }} | gh auth login --with-token
# # Replace '{/number}' with '/123/commits'
# PULL_URL=${API_PR_URL/\{\/number\}/\/$PR_NR\/commits}
# THE_COMMAND="gh api -H '$API_HEADER' '$PULL_URL' --jq '$JQ_FILTER'"
# echo "COMMAND: gh api -H '$API_HEADER' '$PULL_URL' --jq '$JQ_FILTER'"
# # echo "::set-output name=commits::$(gh api -H '${API_HEADER}' '${PULL_URL}' --jq '${JQ_FILTER}')"
# echo "ENV_ALL_COMMITS=$(gh api -H \"$API_HEADER\" \"$PULL_URL\" --jq \"$JQ_FILTER\")" >> $GITHUB_ENV
# - name: Log the output
# run: |
# # echo ${{ steps.get_pr_commits.outputs.commits }}
# echo $ENV_ALL_COMMITS
# - name: Has commit with title containing '${{ github.event.inputs.search_string }}'
# # env:
# # THE_COMMITS: ${{ fromJSON( steps.get_pr_commits.outputs.commits ) }}
# # if: ${{ contains(github.event.issue.labels.*.name, 'bug') }}
# if: ${{ contains( fromJSON( steps.get_pr_commits.outputs.commits ).*.title, github.event.inputs.search_string ) }}
# run: echo 'True'