stefanzweifel / git-auto-commit-action

Automatically commit and push changed files back to GitHub with this GitHub Action for the 80% use case.
MIT License
1.92k stars 224 forks source link

Seems commit_hash output is not set #251

Closed knutole closed 1 year ago

knutole commented 1 year ago

git-auto-commit Version

v4 fd157da78fa13d9383e5580d1fd1184d89554b51

Machine Type

Ubuntu (eg. ubuntu-latest)

Bug description

After commit, the steps.auto-commit-action.outputs.commit_hash variable does not contain the SHA, as promised in docs.

Steps to reproduce

Run workflow.

Tried solutions

Adding a id to the job fixes the issue actually. I guess I read the docs wrong, the id of the step was inferred. Perhaps improve docs?

Example Workflow

on:
  # Triggers the workflow on pull request events but only for the master branch
  pull_request:
    branches: [master]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  bump:
    runs-on: ubuntu-latest
    outputs:
      sha: ${{ steps.sha.outputs.sha }}
      test: ${{ steps.sha.outputs.test }}
    steps:
      - name: Checkout Github repository
        uses: actions/checkout@v2
        with:
          ref: ${{ github.head_ref }}

      - name: Bump version
        id: bump-version
        run: |
          npm version patch

      - uses: stefanzweifel/git-auto-commit-action@v4
        name: Commit version ${{ env.motivero_version }}
        with:
          commit_message: Bumped version

      - name: Get SHA
        id: sha
        run: |
          SHA=${{steps.auto-commit-action.outputs.commit_hash }}
          echo SHA: $SHA
          echo "::set-output name=sha::$SHA"
          echo "::set-output name=test::IAMTEST"

  build:
    runs-on: ubuntu-latest
    needs: bump
    steps:
      - name: Check SHA "${{ env.motivero_version_sha }}"
        run: |
          echo "test env: ${{needs.bump.outputs.test}}"
          echo "job sha: ${{needs.bump.outputs.sha}}"

Relevant log output


# build
2022-10-13T14:03:07.6378683Z ##[group]Run echo "test env: IAMTEST"
2022-10-13T14:03:07.6379668Z echo "test env: IAMTEST" [0m
2022-10-13T14:03:07.6380501Z echo "job sha: " [0m
2022-10-13T14:03:07.6436504Z shell: /usr/bin/bash -e ***0***
stefanzweifel commented 1 year ago

The git-auto-commit-action step in your workflow doesn't have an ID. So ${{steps.auto-commit-action.outputs.commit_hash }} will return nothing.

Add an ID and it should work.

      - uses: stefanzweifel/git-auto-commit-action@v4
+         id: auto-commit-action
        name: Commit version ${{ env.motivero_version }}
        with:
          commit_message: Bumped version

Note that set-output is being deprecated by GitHub.

As this way only just announced, I don't know how this will exactly impact the Action.

knutole commented 1 year ago

Yes thanks, just figured it out. I wrongly assumed the id was inferred.