Icarus
Icarus

Reputation: 19

Codemagic can't access GitHub repo with permission denied error

I got a permission error even when I got my token and put it on the environment variables in Codemagic

my error

remote: Permission to Icarus-conf/fc_lang.git denied to Icarus-conf.
fatal: unable to access 'https://github.com/Icarus-conf/fc_lang/': The requested URL returned error: 403

my codemagic.yaml file

workflows:
  build_and_deploy:
    name: Build and Deploy to GitHub Pages
    environment:
      flutter: stable
      groups:
        - repo_credentials
    scripts:
      - name: Install dependencies
        script: |
          flutter pub get

      - name: Build web
        script: |
          flutter build web --release --no-tree-shake-icons

      - name: Verify build output
        script: |
          if [ ! -d "build/web" ]; then
            echo "Build directory does not exist. Aborting."
            exit 1
          fi
          ls -la build/web

      - name: Configure Git
        script: |
          git config --global user.name "$GIT_USER_NAME"
          git config --global user.email "$GIT_USER_EMAIL"
          git config --global credential.helper 'cache --timeout=3600'
          echo "https://$APP_PASSWORD:@github.com" > ~/.git-credentials

      - name: Checkout web branch
        script: |
          git fetch --all
          if git show-ref --verify --quiet refs/heads/web-branch; then
            git checkout web-branch
          else
            git checkout -b web-branch
          fi

      - name: Copy built files to web branch
        script: |
          rm -rf *  # Clear the web branch directory
          cp -R build/web/* .
          git add .
          git commit -m "Update web branch with latest changes from main" || echo "No changes to commit"
          git push origin web-branch

      - name: Deploy to GitHub Pages
        script: |
          git checkout -B gh-pages
          git add .
          git commit -m "Deploy to GitHub Pages" || echo "No changes to commit"
          git push --force origin gh-pages

artifacts:
  - build/web

I got a permission error even when I got my token and put it on the environment variables in Codemagic.

Upvotes: 0

Views: 128

Answers (1)

Mikhail Tokarev
Mikhail Tokarev

Reputation: 3306

from the yaml file you shared, next line doesn't look correct to me

echo "https://$APP_PASSWORD:@github.com" > ~/.git-credentials

Namely it should be something like $GIT_USER_NAME:$APP_PASSWORD but you have password as a username.

Also you can consider using GitHub CLI tools for authentication https://cli.github.com/manual/gh_auth_login

Upvotes: 0

Related Questions