merged gathering git info into singular step

This commit is contained in:
David Hiendl 2023-10-24 11:23:03 +02:00
parent 051e50160f
commit 9d3e47920f

View File

@ -9,32 +9,32 @@ inputs:
outputs:
git_is_default:
value: ${{ steps.default.outputs.is_default }}
value: ${{ steps.information_git.outputs.git_is_default }}
description: 'Returns `"true"` if the current branch is the default else `"false"`.'
git_is_tag:
value: ${{ steps.tag.outputs.is_tag }}
value: ${{ steps.information_git.outputs.git_is_tag }}
description: 'Returns `"true"` if the current branch is a tag else `"false"`.'
git_default_branch:
value: ${{ steps.default.outputs.default_branch }}
value: ${{ steps.information_git.outputs.git_default_branch }}
description: 'The default branch name e.g `main` OR `master`'
git_current_branch:
value: ${{ steps.current_branch.outputs.current_branch }}
value: ${{ steps.information_git.outputs.git_current_branch }}
description: 'The current branch name regardless of event_type e.g `main`, `feature/test`'
git_base_ref_branch:
value: ${{ steps.branch.outputs.base_ref_branch }}
value: ${{ steps.information_git.outputs.git_base_ref_branch }}
description: 'The target branch of a pull request or tag e.g `main`'
git_head_ref_branch:
value: ${{ steps.branch.outputs.head_ref_branch }}
value: ${{ steps.information_git.outputs.git_head_ref_branch }}
description: 'The source branch of a pull request e.g `feature/test`'
git_ref_branch:
value: ${{ steps.branch.outputs.ref_branch }}
value: ${{ steps.information_git.outputs.git_ref_branch }}
description: 'The branch that triggered the workflow run. e.g `1/merge`, `main`'
git_tag:
value: ${{ steps.tag.outputs.tag }}
value: ${{ steps.information_git.outputs.git_tag }}
description: 'The tag that triggered the workflow run. e.g `v0.0.1`, `0.0.1`'
ci_hostname:
value: ${{ steps.ci_hostname.outputs.ci_hostname }}
value: ${{ steps.information_hostname.outputs.ci_hostname }}
description: 'ci server hostname without http(s) prefix'
# TODO add ci_registry variable
@ -47,8 +47,13 @@ runs:
shell: bash
run: echo dummy info step executed
- id: branch
- id: information_git
shell: bash
env:
ACTIONS_STEP_DEBUG: "true"
run: |
echo gathering git information...
# "Set branch names..."
if [[ "${{ github.ref }}" != "refs/tags/"* ]]; then
BASE_REF=$(printf "%q" "${{ github.event.pull_request.base.ref || github.base_ref }}")
@ -73,27 +78,21 @@ runs:
echo "git_base_ref_branch=$(eval printf "%s" "$BASE_REF")" >> "$GITHUB_OUTPUT"
echo "::debug::git_base_ref_branch=$BASE_REF"
fi
shell: bash
- id: current_branch
run: |
# "Set the current branch name..."
if [[ "${{ github.ref }}" != "refs/tags/"* ]]; then
if [[ ${{ github.event_name }} == *"pull_request"* ]]; then
echo "git_current_branch=${{ steps.branch.outputs.git_head_ref_branch }}" >> "$GITHUB_OUTPUT"
echo "::debug::git_current_branch=${{ steps.branch.outputs.git_head_ref_branch }}"
CURRENT_BRANCH=$HEAD_REF
else
echo "git_current_branch=${{ steps.branch.outputs.git_ref_branch }}" >> "$GITHUB_OUTPUT"
echo "::debug::git_current_branch=${{ steps.branch.outputs.git_ref_branch }}"
CURRENT_BRANCH=$REF_BRANCH
fi
echo "git_current_branch=$CURRENT_BRANCH" >> "$GITHUB_OUTPUT"
echo "::debug::git_current_branch=$CURRENT_BRANCH"
fi
shell: bash
- id: default
run: |
# "Set the default branch name..."
if [[ "${{ github.ref }}" != "refs/tags/"* ]]; then
if [[ "${{ steps.current_branch.outputs.current_branch }}" == "${{ github.event.repository.default_branch }}" && "${{ github.event.pull_request.head.repo.fork }}" != "true" ]]; then
if [[ "$CURRENT_BRANCH" == "${{ github.event.repository.default_branch }}" && "${{ github.event.pull_request.head.repo.fork }}" != "true" ]]; then
echo "git_is_default=true" >> "$GITHUB_OUTPUT"
echo "git_default_branch=${{ github.event.repository.default_branch }}" >> "$GITHUB_OUTPUT"
echo "::debug::git_is_default=true"
@ -105,10 +104,7 @@ runs:
echo "::debug::git_default_branch=${{ github.event.repository.default_branch }}"
fi
fi
shell: bash
- id: tag
run: |
# "Set the tag name..."
if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
REF=$(printf "%q" "${{ github.ref }}")
@ -121,9 +117,8 @@ runs:
echo "git_is_tag=false" >> "$GITHUB_OUTPUT"
echo "::debug::git_is_tag=false"
fi
shell: bash
- id: ci_hostname
- id: information_hostname
run: |
CI_HOSTNAME=$(echo $GITHUB_SERVER_URL | sed -e 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/')
echo "ci_hostname=$CI_HOSTNAME" >> "$GITHUB_OUTPUT"