EndBug / add-and-commit

:octocat: Automatically commit changes made in your workflow run directly to your repo
MIT License
1.14k stars 117 forks source link

endbug/add-and-commit@v5 #667

Closed ramchris closed 2 hours ago

ramchris commented 2 days ago

I see an exception in the logs when my project uses this action. Can you please advise if something is wrong with the way we are using this action.

Action

name: Prettier
run-name: Making things Prettier
on:
  pull_request:

jobs:
  authifactory:
    runs-on: [ one-thd-onprem-np ]
    outputs:
      ARTIFACTORY_TOKEN: ${{ steps.authifactory.outputs.ARTIFACTORY_TOKEN }}
    steps:
      - name: Authifactory
        id: authifactory
        uses: one-thd/authifactory-action@v2.1
        with:
          domain: npm
          token-only: true
          ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USER }}
          ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}

  format:
    runs-on: [ one-thd-onprem-np ]
    needs: [ authifactory ]
    strategy:
      matrix:
        node-version: [ 18.x ]
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
          always-auth: true
          registry-url: https://npm.artifactory.homedepot.com/artifactory/api/npm/npm/
          cache: 'npm'

      - name: Install dependencies
        run: npm ci
        env:
          ARTIFACTORY_NPM_TOKEN: ${{ needs.authifactory.outputs.ARTIFACTORY_TOKEN }}

      - name: Formatting
        run: npm run format

      - name: Commit changes
        uses: endbug/add-and-commit@v5
        with:
          add: 'src'
          message: "chore: Apply formatting changes"

Exception I see in github console.

Run endbug/add-and-commit@v5 with: add: src message: chore: Apply formatting changes cwd: . pull_strategy: --no-rebase env: NPM_CONFIG_USERCONFIG: /runner/_work/_temp/.npmrc NODE_AUTH_TOKEN: XXXXX-XXXXX-XXXXX-XXXXX Warning: The set-output command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/[2](https://github.com/one-thd/myAssortment-ui/actions/runs/11686733964/job/32543247267?pr=1131#step:7:2)022-10-11-github-actions-deprecating-save-state-and-set-output-commands/ Warning: The set-output command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/ Warning: The set-output command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/ Running in /runner/_work/myAssortment-ui/myAssortment-ui Warning: The GITHUB_TOKEN env variable is missing: the action may not work as expected.

Unable to get commit from workflow event: trying with the GitHub API... Request error: Warning: Unable to fetch author info: couldn't fetch commit. Using 'Add & Commit Action actions@github.com' as author. Using "chore: Apply formatting changes" as commit message. Running for a PR, the action will use 'bug-MA-2444' as ref. Internal logs Outputs Error: Error: There is no tracking information for the current branch. Please specify which branch you want to merge with. See git-pull(1) for details.

git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

git branch --set-upstream-to=origin/<branch> bug-MA-2444
EndBug commented 1 day ago

Seems like you're using a self-hosted runner that, as written in the warnings, does not contain the GITHUB_TOKEN env variable. You need to provide a GitHub token for the action to be able to run. Also, it seems like you're using a very old version of the action, please upgrade to the latest.

If you need to use a Personal Access Token, you can plug it into the github_token input: https://github.com/EndBug/add-and-commit/blob/43eaafb140bdacd4907fa7384fdd5cd271f58171/action.yml#L64-L67

ramchris commented 2 hours ago

Thanks and it fixed the issue we see.