Skip to content

Commit

Permalink
feat: use GITHUB_REF_POINT as variable for the branch name (#149)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Change the behavior of GITHUB_REF_NAME to match the default GitHub Action behavior,
BREAKING CHANGE: Introduce GITHUB_REF_POINT as a replacement for GITHUB_REF_NAME to match this GitHub Action behavior in v4.
  • Loading branch information
rlespinasse committed Nov 5, 2024
1 parent 63a442f commit aba9f8d
Show file tree
Hide file tree
Showing 9 changed files with 310 additions and 274 deletions.
1 change: 1 addition & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
uses: github/super-linter@v7
env:
VALIDATE_ALL_CODEBASE: false
VALIDATE_JSCPD: false
VALIDATE_JSON_PRETTIER: false
VALIDATE_MARKDOWN_PRETTIER: false
DEFAULT_BRANCH: v5.x
Expand Down
28 changes: 16 additions & 12 deletions .github/workflows/v5-tests-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ jobs:
[[ "${{ env.GITHUB_EVENT_REF_SLUG_URL_CS }}" == "${{ env.V4_GITHUB_EVENT_REF_SLUG_URL_CS }}" ]]
shell: bash

- name: Validate // Ref Name
- name: Validate // Ref Point
run: |
[[ "${{ env.GITHUB_REF_NAME }}" == "${{ env.V4_GITHUB_REF_NAME }}" ]]
[[ "${{ env.GITHUB_REF_NAME_SLUG }}" == "${{ env.V4_GITHUB_REF_NAME_SLUG }}" ]]
[[ "${{ env.GITHUB_REF_NAME_SLUG_URL }}" == "${{ env.V4_GITHUB_REF_NAME_SLUG_URL }}" ]]
[[ "${{ env.GITHUB_REF_NAME_SLUG_CS }}" == "${{ env.V4_GITHUB_REF_NAME_SLUG_CS }}" ]]
[[ "${{ env.GITHUB_REF_NAME_SLUG_URL_CS }}" == "${{ env.V4_GITHUB_REF_NAME_SLUG_URL_CS }}" ]]
[[ "${{ env.GITHUB_REF_POINT }}" == "${{ env.V4_GITHUB_REF_NAME }}" ]]
[[ "${{ env.GITHUB_REF_POINT_SLUG }}" == "${{ env.V4_GITHUB_REF_NAME_SLUG }}" ]]
[[ "${{ env.GITHUB_REF_POINT_SLUG_URL }}" == "${{ env.V4_GITHUB_REF_NAME_SLUG_URL }}" ]]
[[ "${{ env.GITHUB_REF_POINT_SLUG_CS }}" == "${{ env.V4_GITHUB_REF_NAME_SLUG_CS }}" ]]
[[ "${{ env.GITHUB_REF_POINT_SLUG_URL_CS }}" == "${{ env.V4_GITHUB_REF_NAME_SLUG_URL_CS }}" ]]
shell: bash

- name: Validate // Short SHA variables
Expand Down Expand Up @@ -139,6 +139,7 @@ jobs:
echo "repository owner : ${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG }}"
echo "repository name : ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}"
echo "ref : ${{ env.GITHUB_REF_SLUG }}"
echo "ref name : ${{ env.GITHUB_REF_NAME_SLUG }}"
echo "head ref : ${{ env.GITHUB_HEAD_REF_SLUG }}"
echo "base ref : ${{ env.GITHUB_BASE_REF_SLUG }}"
echo "event ref : ${{ env.GITHUB_EVENT_REF_SLUG }}"
Expand All @@ -150,6 +151,7 @@ jobs:
echo "repository owner : ${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG_CS }}"
echo "repository name : ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_CS }}"
echo "ref : ${{ env.GITHUB_REF_SLUG_CS }}"
echo "ref name : ${{ env.GITHUB_REF_NAME_SLUG_CS }}"
echo "head ref : ${{ env.GITHUB_HEAD_REF_SLUG_CS }}"
echo "base ref : ${{ env.GITHUB_BASE_REF_SLUG_CS }}"
echo "event ref : ${{ env.GITHUB_EVENT_REF_SLUG_CS }}"
Expand All @@ -161,6 +163,7 @@ jobs:
echo "repository owner : ${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG_URL }}"
echo "repository name : ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}"
echo "ref : ${{ env.GITHUB_REF_SLUG_URL }}"
echo "ref name : ${{ env.GITHUB_REF_NAME_SLUG_URL }}"
echo "head ref : ${{ env.GITHUB_HEAD_REF_SLUG_URL }}"
echo "base ref : ${{ env.GITHUB_BASE_REF_SLUG_URL }}"
echo "event ref : ${{ env.GITHUB_EVENT_REF_SLUG_URL }}"
Expand All @@ -172,18 +175,19 @@ jobs:
echo "repository owner : ${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG_URL_CS }}"
echo "repository name : ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL_CS }}"
echo "ref : ${{ env.GITHUB_REF_SLUG_URL_CS }}"
echo "ref name : ${{ env.GITHUB_REF_NAME_SLUG_URL_CS }}"
echo "head ref : ${{ env.GITHUB_HEAD_REF_SLUG_URL_CS }}"
echo "base ref : ${{ env.GITHUB_BASE_REF_SLUG_URL_CS }}"
echo "event ref : ${{ env.GITHUB_EVENT_REF_SLUG_URL_CS }}"
shell: bash

- name: Ref Name
- name: Ref Point
run: |
echo "raw : ${{ env.GITHUB_REF_NAME }}"
echo "slug : ${{ env.GITHUB_REF_NAME_SLUG }}"
echo "slug url : ${{ env.GITHUB_REF_NAME_SLUG_URL }}"
echo "slug (Case Sensitive) : ${{ env.GITHUB_REF_NAME_SLUG_CS }}"
echo "slug url (Case Sensitive) : ${{ env.GITHUB_REF_NAME_SLUG_URL_CS }}"
echo "raw : ${{ env.GITHUB_REF_POINT }}"
echo "slug : ${{ env.GITHUB_REF_POINT_SLUG }}"
echo "slug url : ${{ env.GITHUB_REF_POINT_SLUG_URL }}"
echo "slug (Case Sensitive) : ${{ env.GITHUB_REF_POINT_SLUG_CS }}"
echo "slug url (Case Sensitive) : ${{ env.GITHUB_REF_POINT_SLUG_URL_CS }}"
shell: bash

- name: Short SHA variables
Expand Down
260 changes: 127 additions & 133 deletions README.md

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ runs:
- uses: rlespinasse/[email protected]
with:
key: GITHUB_REF_NAME
# Related to https://github.com/rlespinasse/github-slug-action/issues/104
value: ${{ github.ref_name }}
prefix: ${{ inputs.prefix }}
slug-maxlength: ${{ inputs.slug-maxlength }}
- uses: rlespinasse/[email protected]
with:
key: GITHUB_REF_POINT
value: ${{ env.GITHUB_HEAD_REF_RAW || env.GITHUB_REF_NAME_RAW }}
prefix: ${{ inputs.prefix }}
slug-maxlength: ${{ inputs.slug-maxlength }}
Expand Down
55 changes: 28 additions & 27 deletions docs/github-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,25 @@ All `GitHub` variables availables in your workflow in addition of ones exposed b
- [Action-managed Event Variables](#action-managed-event-variables)
- [create](#create)
- [delete](#delete)
- [pull_request](#pull_request)
- [pull_request_review](#pull_request_review)
- [pull_request_review_comment](#pull_request_review_comment)
- [pull_request_target](#pull_request_target)
- [pull\_request](#pull_request)
- [pull\_request\_review](#pull_request_review)
- [pull\_request\_review\_comment](#pull_request_review_comment)
- [pull\_request\_target](#pull_request_target)

## Default environment variables

Read the official documentation about [Default environment variables][1].

### Action-managed Environment Variables

| Action-managed Variables | Can be suffix by |
| ------------------------ | -------------------- |
| GITHUB_REPOSITORY | `_SLUG`, `_SLUG_URL` |
| GITHUB_REF | `_SLUG`, `_SLUG_URL` |
| GITHUB_HEAD_REF | `_SLUG`, `_SLUG_URL` |
| GITHUB_BASE_REF | `_SLUG`, `_SLUG_URL` |
| GITHUB_SHA | `_SHORT` |
| Action-managed Variables | Can be suffix by |
| ------------------------ | --------------- |
| GITHUB_REPOSITORY | `_SLUG`, `_SLUG_URL` |
| GITHUB_REF | `_SLUG`, `_SLUG_URL` |
| GITHUB_REF_NAME | `_SLUG`, `_SLUG_URL` |
| GITHUB_HEAD_REF | `_SLUG`, `_SLUG_URL` |
| GITHUB_BASE_REF | `_SLUG`, `_SLUG_URL` |
| GITHUB_SHA | `_SHORT` |

## Variables from events

Expand All @@ -41,50 +42,50 @@ Read the official documentation about [Events that trigger workflows][2].

Checkout [create][3] webhook payload content

| Action-managed Variables | Available as |
| ------------------------ | ------------------------- |
| github.event.ref | GITHUB_EVENT_REF_SLUG |
| github.event.ref | GITHUB_EVENT_REF_SLUG_URL |
| Action-managed Variables | Available as |
| ------------------------ | ------------ |
| github.event.ref | GITHUB_EVENT_REF_SLUG |
| github.event.ref | GITHUB_EVENT_REF_SLUG_URL |

#### delete

Checkout [delete][4] webhook payload content

| Action-managed Variables | Available as |
| ------------------------ | ------------------------- |
| github.event.ref | GITHUB_EVENT_REF_SLUG |
| github.event.ref | GITHUB_EVENT_REF_SLUG_URL |
| Action-managed Variables | Available as |
| ------------------------ | ------------ |
| github.event.ref | GITHUB_EVENT_REF_SLUG |
| github.event.ref | GITHUB_EVENT_REF_SLUG_URL |

#### pull_request

Checkout [pull_request][5] webhook payload content

| Action-managed Variables | Available as |
| ---------------------------------- | ---------------------------------------- |
| Action-managed Variables | Available as |
| ------------------------ | ------------ |
| github.event.pull_request.head.sha | GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT |

#### pull_request_review

Checkout [pull_request_review][6] webhook payload content

| Action-managed Variables | Available as |
| ---------------------------------- | ---------------------------------------- |
| Action-managed Variables | Available as |
| ------------------------ | ------------ |
| github.event.pull_request.head.sha | GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT |

#### pull_request_review_comment

Checkout [pull_request_review_comment][7] webhook payload content

| Action-managed Variables | Available as |
| ---------------------------------- | ---------------------------------------- |
| Action-managed Variables | Available as |
| ------------------------ | ------------ |
| github.event.pull_request.head.sha | GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT |

#### pull_request_target

Checkout [pull_request][5] webhook payload content

| Action-managed Variables | Available as |
| ---------------------------------- | ---------------------------------------- |
| Action-managed Variables | Available as |
| ------------------------ | ------------ |
| github.event.pull_request.head.sha | GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT |

[1]: https://docs.github.com/en/actions/reference/environment-variables#default-environment-variables
Expand Down
24 changes: 12 additions & 12 deletions docs/partial-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@

- [Partial Variables](#partial-variables)
- [Table of Contents](#table-of-contents)
- [GITHUB_REPOSITORY_OWNER_PART](#github_repository_owner_part)
- [GITHUB_REPOSITORY_NAME_PART](#github_repository_name_part)
- [GITHUB\_REPOSITORY\_OWNER\_PART](#github_repository_owner_part)
- [GITHUB\_REPOSITORY\_NAME\_PART](#github_repository_name_part)

## GITHUB_REPOSITORY_OWNER_PART

Owner part of the environment variable **GITHUB_REPOSITORY**

| GITHUB_REPOSITORY | GITHUB_REPOSITORY_OWNER_PART |
| ---------------------------- | ---------------------------- |
| octocat/Hello-World | octocat |
| rlespinasse/Hello-World.go | rlespinasse |
| AnotherPerson/SomeRepository | AnotherPerson |
| GITHUB_REPOSITORY | GITHUB_REPOSITORY_OWNER_PART |
| ----------------- | ---------------------------- |
| octocat/Hello-World | octocat |
| rlespinasse/Hello-World.go | rlespinasse |
| AnotherPerson/SomeRepository | AnotherPerson |

## GITHUB_REPOSITORY_NAME_PART

Repository name part of the environment variable **GITHUB_REPOSITORY**

| GITHUB_REPOSITORY | GITHUB_REPOSITORY_NAME_PART |
| ---------------------------- | --------------------------- |
| octocat/Hello-World | Hello-World |
| rlespinasse/Hello-World.go | Hello-World.go |
| AnotherPerson/SomeRepository | SomeRepository |
| GITHUB_REPOSITORY | GITHUB_REPOSITORY_NAME_PART |
| ----------------- | --------------------------- |
| octocat/Hello-World | Hello-World |
| rlespinasse/Hello-World.go | Hello-World.go |
| AnotherPerson/SomeRepository | SomeRepository |
16 changes: 8 additions & 8 deletions docs/short-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@

- [Short Variables](#short-variables)
- [Table of Contents](#table-of-contents)
- [GITHUB_SHA_SHORT](#github_sha_short)
- [GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT](#github_event_pull_request_head_sha_short)
- [GITHUB\_SHA\_SHORT](#github_sha_short)
- [GITHUB\_EVENT\_PULL\_REQUEST\_HEAD\_SHA\_SHORT](#github_event_pull_request_head_sha_short)

## GITHUB_SHA_SHORT

Short the environment variable **GITHUB_SHA**

The commit SHA that triggered the workflow

| GITHUB_SHA | GITHUB_SHA_SHORT |
| ---------------------------------------- | ---------------- |
| ffac537e6cbbf934b08745a378932722df287a53 | ffac537e |
| GITHUB_SHA | GITHUB_SHA_SHORT |
| ---------- | ---------------- |
| ffac537e6cbbf934b08745a378932722df287a53 | ffac537e |

## GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT

Short the value of `github.event.pull_request.head.sha` that represents the last commit
used for triggering an action for a pull request.

| github.event.pull_request.head.sha | GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT |
| ---------------------------------------- | ---------------------------------------- |
| ffac537e6cbbf934b08745a378932722df287a53 | ffac537e |
| github.event.pull_request.head.sha | GITHUB_EVENT_PULL_REQUEST_HEAD_SHA_SHORT |
| ---------------------------------- | ---------------------------------------- |
| ffac537e6cbbf934b08745a378932722df287a53 | ffac537e |
Loading

0 comments on commit aba9f8d

Please sign in to comment.