From d1ddfe37aa52dd37eeb405e99d16e3094baf156c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=BCller?= Date: Thu, 9 Apr 2026 20:28:39 +0200 Subject: [PATCH] Parse the event.json of an action (e.g. push) --- lnx/parse-event/action.yml | 38 ++++++++++++++++++++++++++++++++++++++ win/parse-event/action.yml | 31 +++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 lnx/parse-event/action.yml create mode 100644 win/parse-event/action.yml diff --git a/lnx/parse-event/action.yml b/lnx/parse-event/action.yml new file mode 100644 index 0000000..912b7c2 --- /dev/null +++ b/lnx/parse-event/action.yml @@ -0,0 +1,38 @@ +name: 'parse-event' +description: 'Parses a JSON file, that contains all information about the last event.' + +outputs: + base-commit: + description: 'The hash of the base commit of the event. This is the commit that was previously at the head of the branch before the event.' + value: ${{ steps.parse.outputs.hash }} + fetch-depth: + description: 'The number of commits needed to get the whole diff of the event.' + value: ${{ steps.parse.outputs.count }} + +runs: + using: 'composite' + steps: + - name: Install jq + shell: bash + run: | + apt-get update &> /dev/null + apt-get install -y jq &> /dev/null + echo "$(which jq): $(jq --version)" + + - name: Parse event + id: parse + shell: bash + run: | + hash=$(jq -r '.before' "${{ github.event_path }}") + count=$(jq -r '.commits | length + 1' "${{ github.event_path }}") + serverUrl="${{ github.server_url }}" + host=${serverUrl#*://} + + echo "OUT: hash=$hash" + echo "hash=$hash" >> $GITHUB_OUTPUT + + echo "OUT: count=$count" + echo "count=$count" >> $GITHUB_OUTPUT + + echo "ENV: CI_SERVER_HOST=$host" + echo "CI_SERVER_HOST=$host" >> $GITHUB_ENV \ No newline at end of file diff --git a/win/parse-event/action.yml b/win/parse-event/action.yml new file mode 100644 index 0000000..716835e --- /dev/null +++ b/win/parse-event/action.yml @@ -0,0 +1,31 @@ +name: 'parse-event' +description: 'Parses a JSON file, that contains all information about the last event.' + +outputs: + base-commit: + description: 'The hash of the base commit of the event. This is the commit that was previously at the head of the branch before the event.' + value: ${{ steps.parse.outputs.hash }} + fetch-depth: + description: 'The number of commits needed to get the whole diff of the event.' + value: ${{ steps.parse.outputs.count }} + +runs: + using: 'composite' + steps: + - name: Parse event + id: parse + shell: powershell + run: | + chcp 65001 > $null + $event = Get-Content "${{ github.event_path }}" | ConvertFrom-Json + $serverUrl = "${{ github.server_url }}" + $host = $serverUrl -replace '.*://', '' + + Write-Output "OUT: hash=$($event.before)" + Write-Output "hash=$($event.before)" | Add-Content -Path $env:GITHUB_OUTPUT + + Write-Output "OUT: count=$($event.commits.Count + 1)" + Write-Output "count=$($event.commits.Count + 1)" | Add-Content -Path $env:GITHUB_OUTPUT + + Write-Output "ENV: CI_SERVER_HOST=$host" + Write-Output "CI_SERVER_HOST=$host" | Add-Content -Path $env:GITHUB_ENV \ No newline at end of file