Skip to content

dora-metrics-actions #9

dora-metrics-actions

dora-metrics-actions #9

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
uses: DeveloperMetrics/deployment-frequency@main
id: deployment-frequency2
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
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