-
Notifications
You must be signed in to change notification settings - Fork 0
78 lines (67 loc) · 2.67 KB
/
dora-metrics-actions.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
name: dora-metrics-actions
on:
workflow_dispatch:
permissions:
contents: write
actions: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: deployment-frequency
uses: joshjohanning/deployment-frequency@main
id: deployment-frequency
with:
workflows: 'CI'
owner-repo: '${{ github.repository }}'
actions-token: "${{ github.token }}"
- name: deployment-frequency-pat
uses: joshjohanning/deployment-frequency@main
id: deployment-frequency-pat
with:
workflows: 'CI'
owner-repo: '${{ github.repository }}'
pat-token: "${{ github.token }}"
- name: lead-time-for-changes
uses: joshjohanning/lead-time-for-changes@main
id: lead-time
with:
workflows: 'CI'
owner-repo: '${{ github.repository }}'
actions-token: "${{ github.token }}"
- name: lead-time-for-changes
uses: joshjohanning/lead-time-for-changes@main
id: lead-time-pat
with:
workflows: 'CI'
owner-repo: '${{ github.repository }}'
pat-token: "${{ github.token }}"
- name: add to readme
run: |
readme=README.md
# get SHA256 before
beforeHash=$(sha256sum $readme | awk '{ print $1 }')
# Define start and end markers
startMarker="<!-- Start Dora Metrics -->"
endMarker="<!-- End Dora Metrics -->"
# Read the content of dora-deployment-frequency.md and dora-lead-time.md into a variable
replacement=$(cat ${{ steps.deployment-frequency.outputs.markdown-file }} ${{ steps.lead-time.outputs.markdown-file }})
# Escape special characters in the replacement text
replacementEscaped=$(printf '%s\n' "$replacement" | perl -pe 's/([\\\/\$\(\)@])/\\$1/g')
# Use perl to replace the text between the markers
perl -i -pe "BEGIN{undef $/;} s/\Q$startMarker\E.*?\Q$endMarker\E/$startMarker\n$replacementEscaped\n$endMarker/smg" $readme
# get SHA256 after
afterHash=$(sha256sum $readme | awk '{ print $1 }')
# Compare the hashes and commit if required
if [ "$afterHash" = "$beforeHash" ]; then
echo "The hashes are equal - exiting script"
exit 0
else
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add $readme
git commit -m "docs: updating DORA metrics
[no ci]"
git push
fi