github-sync icon indicating copy to clipboard operation
github-sync copied to clipboard

Sync fails with "Set the GITHUB_TOKEN environment variable."

Open ajshastri opened this issue 2 years ago • 1 comments

Hello,

I used the following repo-sync.yml

# File: .github/workflows/repo-sync.yml
name: Repo Sync

on:
  schedule:
  - cron:  "*/5 * * * *"
  workflow_dispatch:

jobs:
  repo-sync:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
        persist-credentials: false
    - name: repo-sync
      uses: repo-sync/github-sync@v2
      with:
        source_repo: ${{ secrets.SOURCE_REPO }}
        source_branch: ${{ secrets.INTERMEDIATE_BRANCH }}
        destination_branch: "*"
        github_token: ${{ secrets.PAT }}
        sync_tags: "true"

My actions fail with


Run repo-sync/github-sync@v[2](https://github.com/ajshastri/gnumake/actions/runs/4110292610/jobs/7092964910#step:4:2)
  with:
    destination_branch: *
    sync_tags: true
/usr/bin/docker run --name ghcrioreposyncgithubsyncv2[3](https://github.com/ajshastri/gnumake/actions/runs/4110292610/jobs/7092964910#step:4:3)0_97009a --label [4](https://github.com/ajshastri/gnumake/actions/runs/4110292610/jobs/7092964910#step:4:4)98[5](https://github.com/ajshastri/gnumake/actions/runs/4110292610/jobs/7092964910#step:4:6)9c --workdir /github/workspace --rm -e "INPUT_SOURCE_REPO" -e "INPUT_SOURCE_BRANCH" -e "INPUT_DESTINATION_BRANCH" -e "INPUT_GITHUB_TOKEN" -e "INPUT_SYNC_TAGS" -e "GITHUB_TOKEN" -e "SYNC_TAGS" -e "HOME" -e "GITHUB_JOB" -e "GITHUB_REF" -e "GITHUB_SHA" -e "GITHUB_REPOSITORY" -e "GITHUB_REPOSITORY_OWNER" -e "GITHUB_REPOSITORY_OWNER_ID" -e "GITHUB_RUN_ID" -e "GITHUB_RUN_NUMBER" -e "GITHUB_RETENTION_DAYS" -e "GITHUB_RUN_ATTEMPT" -e "GITHUB_REPOSITORY_ID" -e "GITHUB_ACTOR_ID" -e "GITHUB_ACTOR" -e "GITHUB_TRIGGERING_ACTOR" -e "GITHUB_WORKFLOW" -e "GITHUB_HEAD_REF" -e "GITHUB_BASE_REF" -e "GITHUB_EVENT_NAME" -e "GITHUB_SERVER_URL" -e "GITHUB_API_URL" -e "GITHUB_GRAPHQL_URL" -e "GITHUB_REF_NAME" -e "GITHUB_REF_PROTECTED" -e "GITHUB_REF_TYPE" -e "GITHUB_WORKFLOW_REF" -e "GITHUB_WORKFLOW_SHA" -e "GITHUB_WORKSPACE" -e "GITHUB_ACTION" -e "GITHUB_EVENT_PATH" -e "GITHUB_ACTION_REPOSITORY" -e "GITHUB_ACTION_REF" -e "GITHUB_PATH" -e "GITHUB_ENV" -e "GITHUB_STEP_SUMMARY" -e "GITHUB_STATE" -e "GITHUB_OUTPUT" -e "RUNNER_OS" -e "RUNNER_ARCH" -e "RUNNER_NAME" -e "RUNNER_TOOL_CACHE" -e "RUNNER_TEMP" -e "RUNNER_WORKSPACE" -e "ACTIONS_RUNTIME_URL" -e "ACTIONS_RUNTIME_TOKEN" -e "ACTIONS_CACHE_URL" -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/gnumake/gnumake":"/github/workspace" ghcr.io/repo-sync/github-sync:v2.3.0  "" ":*"
Set the GITHUB_TOKEN environment variable.

I've set the secrets variables for SOURCE_REPO, INTERMEDIATE_BRANCH and PAT but it seems to want the GITHUB_TOKEN which github will not let me.

ajshastri avatar Feb 07 '23 03:02 ajshastri

Hi, The GITHUB_TOKEN is mandatory so the action can make changes to the destination repository ( The one that you run the action on )

    - name: repo-sync
      env:
        SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
       ...

Make sure to give the Github Action the right permission on the repository by following steps below :

  • Go to your repository settings on GitHub.
  • Navigate to "Actions" > "General".
  • Under "Workflow permissions", select "Read and write permissions".

WillyRL avatar Apr 15 '24 07:04 WillyRL

Thank you @WillyRL, that is the correct answer :)

heiskr avatar May 20 '24 17:05 heiskr