Trying to update the version.go file with the release tag from GitHub actions but its failing

47 views Asked by At

I'm trying to update version in a go file but it's failing with this error:

Run actions/github-script@v6
SyntaxError: Unexpected identifier
    at new AsyncFunction (<anonymous>)
    at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:15143:16)
    at main (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:15236:26)
    at /home/runner/work/_actions/actions/github-script/v6/dist/index.js:15217:1
    at /home/runner/work/_actions/actions/github-script/v6/dist/index.js:15268:3
    at Object.<anonymous> (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:15271:12)
    at Module._compile (node:internal/modules/cjs/loader:1198:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
    at Module.load (node:internal/modules/cjs/loader:1076:32)
    at Function.Module._load (node:internal/modules/cjs/loader:911:12)
Error: Unhandled error: SyntaxError: Unexpected identifier
##[debug]Node Action run completed with exit code 1
##[debug]Finishing: Run actions/github-script@v6

Could you please explain what's wrong with the workflow and how can we can it?

Here's my workflow:

name: Update Values on Tag
        
on:
  push:
    tags:
      - 'v*' # Trigger only in case of new tag

jobs:
  update_values:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/github-script@v6
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            git config --global user.email "[email protected]"
            git config --global user.name "Github actions"
            echo "Release Tag: ${{ github.ref_name }}"
            release_tag="${{ github.ref_name }}"
            # Update the value in the specified file (replace with your details)
            sed -i "s/const version = .*/const version = \"$release_tag\"/" ./hackkerRankSolutions/version.go
            git add version.go
            git commit -m "Update version to $release_tag in actions.yaml"
            git push origin main
1

There are 1 answers

4
frennky On BEST ANSWER

You're using actions/github-script@v6 to run shell commands. It's not meant for that.

Try this way:

name: Update version
on:
  push:
    tags:
      - 'v*' # Trigger only in case of new tag
        
jobs:
  update_version:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: Update version
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: |
        git config --global user.email "[email protected]"
        git config --global user.name "Github actions"
        echo "Release Tag: ${{ github.ref_name }}"
        release_tag="${{ github.ref_name }}"
        # Update the value in the specified file (replace with your details)
        sed -i "s/const version = .*/const version = \"$release_tag\"/" ./hackkerRankSolutions/version.go
        git add version.go
        git commit -m "Update version to $release_tag in actions.yaml"
        git push origin main