Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable to override commit sha on github action #829

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nobuhikosawai
Copy link

This PR enables to override SHA on GitHub Action. This PR is to complement #713.

On the issue_comment event, github.sha always refers to the default branch. Therefore, if you want to trigger a chromatic action on a specific PR associated with a particular PR comment, an additional process to fetch both the branch name and sha is required. Currently, you can override the branch name by providing the branchName option, but the sha cannot be overridden. This PR enables it.

The following example shows a way to override a sha with this PR.

on: issue_comment
permissions: read-all
jobs:
  publish_chromatic:
    name: Publish to Chromatic
    runs-on: ubuntu-latest
    steps:
      - id: get-branch
        run: |
          input_string=$(gh pr view 8 --repo nobuhikosawai/ga-test --json headRefOid --json headRefName -q '"branch=\(.headRefName) sha=\(.headRefOid)"')
          branch=$(echo "$input_string" | awk -F ' ' '{split($1, a, "="); split($2, b, "="); print a[2]}')
          sha=$(echo "$input_string" | awk -F ' ' '{split($1, a, "="); split($2, b, "="); print b[2]}')
          echo "branch=$branch" >> $GITHUB_OUTPUT
          echo "sha=$sha" >> $GITHUB_OUTPUT
        env:
          REPO: ${{ github.repository }}
          PR_NO: ${{ github.event.issue.number }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
          ref: ${{ steps.get-branch.outputs.branch }}
      - name: Install dependencies
        run: yarn
      - name: Publish to Chromatic
        uses: chromaui/action@v1
        with:
          projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
          branchName: ${{ steps.get-branch.outputs.branch }}
          commitSha: ${{ steps.get-branch.outputs.sha  }}

@thafryer thafryer force-pushed the override_sha_on_github_action branch from b21c151 to 9b16499 Compare October 4, 2023 14:08
@nobuhikosawai
Copy link
Author

@thafryer If you have some questions or need more clarifications, please do let me know.

@thafryer thafryer force-pushed the override_sha_on_github_action branch from 20f94e1 to fb613f3 Compare November 7, 2023 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant