Parse the event.json of an action (e.g. push)
This commit is contained in:
38
lnx/parse-event/action.yml
Normal file
38
lnx/parse-event/action.yml
Normal file
@@ -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
|
||||||
31
win/parse-event/action.yml
Normal file
31
win/parse-event/action.yml
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user