Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
fix: fix GHA_REF_NAME
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-shunsuke committed Sep 21, 2022
1 parent 3684c87 commit edc1505
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ jobs:
{
"event_name": "push",
"event": {
"ref": "refs/heads/renovate/github.com-aws-aws-sdk-go-1.x",
"sender": {
"login": "suzuki-shunsuke"
},
Expand Down Expand Up @@ -123,16 +124,16 @@ jobs:
[ "$GHA_REPOSITORY_NAME" = gha-trigger ]
- name: Test GHA_SHA
run: |
[ "$GHA_SHA" = 4528ea7ab7a8eef7e596097934a78eab90fb8b33 ]
[ "$GHA_SHA" = a705bd6d8bc3882c983477cb3f20ab74ef8c24c2 ]
- name: Test GHA_COMMIT_STATUS_SHA
run: |
[ "$GHA_COMMIT_STATUS_SHA" = 4528ea7ab7a8eef7e596097934a78eab90fb8b33 ]
- name: Test GHA_REF
run: |
[ "$GHA_REF" = ]
[ "$GHA_REF" = refs/heads/renovate/github.com-aws-aws-sdk-go-1.x ]
- name: Test GHA_REF_NAME
run: |
[ "$GHA_REF_NAME" = ]
[ "$GHA_REF_NAME" = renovate/github.com-aws-aws-sdk-go-1.x ]
- name: Test GHA_ENV
run: |
[ -n "$GHA_ENV" ]
Expand Down Expand Up @@ -178,7 +179,7 @@ jobs:
[ "$GHA_REPOSITORY_NAME" = gha-trigger ]
- name: Test GHA_SHA
run: |
[ "$GHA_SHA" = ]
[ "$GHA_SHA" = "" ]
- name: Test GHA_REF
run: |
[ "$GHA_REF" = v0.1.0 ]
Expand Down
22 changes: 20 additions & 2 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ runs:
GHA_PULL_REQUEST_NUMBER=${{fromJSON(inputs.data).event.pull_request.number}}
EOS
if: startsWith(env.GHA_EVENT_NAME, 'pull_request')

- shell: bash
# GITHUB_REF
# > For workflows triggered by release, this is the release tag created.
Expand All @@ -67,6 +68,7 @@ runs:
GHA_REF_NAME=${{fromJSON(inputs.data).event.release.tag_name}}
EOS
if: env.GHA_EVENT_NAME == 'release'

- shell: bash
# GITHUB_REF
# > For workflows triggered by push, this is the branch or tag ref that was pushed.
Expand All @@ -75,12 +77,28 @@ runs:
# When you delete a branch,
# the SHA in the workflow run (and its associated refs) reverts to the default branch of the repository.
cat << EOS >> "$GITHUB_ENV"
GHA_REF=${{fromJSON(inputs.data).event.ref}}
GHA_REF_NAME=$(basename "${{fromJSON(inputs.data).event.ref}}")
GHA_REF=$REF
GHA_SHA=${{fromJSON(inputs.data).event.head_commit.id}}
GHA_COMMIT_STATUS_SHA=${{fromJSON(inputs.data).event.head_commit.id}}
EOS
if: env.GHA_EVENT_NAME == 'push'
env:
REF: ${{fromJSON(inputs.data).event.ref}}

- shell: bash
run: |
cat << EOS >> "$GITHUB_ENV"
GHA_REF_NAME=${GHA_REF#refs/heads/}
EOS
if: "env.GHA_EVENT_NAME == 'push' && startsWith(env.GHA_REF, 'refs/heads/')"

- shell: bash
run: |
cat << EOS >> "$GITHUB_ENV"
GHA_REF_NAME=${GHA_REF#refs/tags/}
EOS
if: "env.GHA_EVENT_NAME == 'push' && startsWith(env.GHA_REF, 'refs/tags/')"

# TODO GITHUB_REF
# > The branch or tag ref that triggered the workflow run.
# > For other triggers, this is the branch or tag ref that triggered the workflow run.
Expand Down

0 comments on commit edc1505

Please sign in to comment.