actions / github-script

Write workflows scripting the GitHub API in JavaScript
MIT License
4.24k stars 424 forks source link

unable to create commit #431

Closed penglei0 closed 1 year ago

penglei0 commented 1 year ago

Describe the bug Fail to call createCommit

To Reproduce Steps to reproduce the behavior:

Please use the following yaml to reproduce。

jobs:
  use-github-script:
    runs-on: ubuntu-latest
    steps:
        - uses: actions/checkout@v4
          with:
            fetch-depth: 2
        - name: Create a new file
          run: |
            touch ${{github.workspace}}/log.txt
            echo "parent=`git rev-parse HEAD`" >> "$GITHUB_ENV"
            git hash-object -w ${{github.workspace}}/log.txt
            git update-index --add ${{github.workspace}}/log.txt
            echo "object_tree=`git write-tree`" >> "$GITHUB_ENV"
        - name: Commit to repo
          uses: actions/github-script@v6
          with:
            github-token: ${{ secrets.GITHUB_TOKEN }}
            script: |
                const commit_msg = "feat: example of add a file"
                const parent = "${{ env.parent}}";
                const object_tree = "${{ env.object_tree}}"";
                const response = await github.rest.git.createCommit({
                    owner: context.repo.owner,
                    repo: context.repo.repo,
                    message: commit_msg,
                    tree: object_tree,
                    parents: [parent]
                });

Expected behavior expect to run the createCommit successfully

Screenshots

image
station70-daniel commented 1 year ago

type-o my friend, right at

const object_tree = "${{ env.object_tree}}"";
penglei0 commented 1 year ago

type-o my friend, right at

const object_tree = "${{ env.object_tree}}"";

@station70-daniel thanks!