5

I'm stucked trying to launch a Github actions workflow. The Flutter project has a dependency of a custom package. I have this custom package in a Github repository. This is the way I set up this dependency in the pubspec.yaml:

xxxx_package:
git:
  url: git@github.com:USER_NAME/xxxx_package.git
  ref: develop

If I launch flutter pub get command, it ends successful and I can build and execute the app without problems.

But when I send a push to Github and it launches the workflow, the process finish with this error:

Running "flutter pub get" in Project-Flutter...            
Git error. Command: `git clone --mirror git@github.com:xxx/xxxx_package.git /home/runner/.pub-cache/git/cache/xxxx_package-123456789`
stdout: 
stderr: Cloning into bare repository '/home/runner/.pub-cache/git/cache/xxxx_package-123456789'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

This is my actions workflow file:

name: Check merge

on:
  push:
    branches: [ main, develop ]

  pull_request:
    branches: [main, develop]
    

  workflow_dispatch:

jobs:
  build:
    name: flutter environment
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-java@v2
        with:
          distribution: 'zulu'
          java-version: '11'
      - uses: subosito/flutter-action@v2
        with:
          flutter-version: '2.8.1'
      - name: Install dependencies
        run: flutter pub get
      - run: flutter format --set-exit-if-changed .
      - run: flutter analyze .
      - run: flutter test

I have configured the custom package repository to work with shh.

UPDATE 02/17/2022

I tried the @GuiFalourd suggestion but not working.

I've added to both repos (main project and private repo) two secrets (same for both).

  • KNOWN_HOSTS
  • SSH_PRIVATE_KEY -> This is the content -----BEGIN RSA PRIVATE KEY----- ssh-ed25519 "SSH_KEY" -----END RSA PRIVATE KEY-----

But this is the output:

IO  : Finished git. Exit code 128.
| Nothing output on stdout.
| stderr:
| | Cloning into bare repository '/home/runner/.pub-cache/git/cache/xxxx_package-363daa26604baf2e3bfeae08af7d9c7050760631'...
| | Warning: Permanently added the ECDSA host key for IP address 'x.x.x.x' to the list of known hosts.
| | Load key "/home/runner/.ssh/id_rsa": invalid format
| | git@github.com: Permission denied (publickey).
| | fatal: Could not read from remote repository.
| | 
| | Please make sure you have the correct access rights
| | and the repository exists.
Sami Issa
  • 1,695
  • 1
  • 18
  • 29

1 Answers1

3

Well, I've found out the problem. @GuiFalourd putted me in the right way. Was in the secrets values (on github repo page, go to settings -> secrets -> actions -> New repository secret):

  • SSH_PRIVATE_KEY: At the beginnig, I used the command pbcopy < ~/.ssh/id_rsa.pub to get the ssh public key. This was wrong. This secret needs the ssh private key. The correct command is pbcopy < ~/.ssh/id_rsa
  • KNOWN_HOSTS: After launch ssh-keyscan github.com command, it's important to copy the line that belongs to github.com ssh-rsa [KEY]

NOTE: this secrets must exists on all app dependency packages repositories.

I let you here the final version of the workflow yaml file:

name: Check merge

on:
  push:
    branches: [ master, develop ]
    paths:
      - "**.dart"

  pull_request:
    branches: [master, develop]
    paths:
      - "**.dart"

  workflow_dispatch:

jobs:
  build:
    name: flutter environment
    runs-on: ubuntu-latest
    steps:
      - uses: shimataro/ssh-key-action@v2
        with:
          key: ${{ secrets.SSH_PRIVATE_KEY }}
          name: id_rsa
          known_hosts: ${{ secrets.KNOWN_HOSTS }}
      - uses: actions/checkout@v2
      - uses: actions/setup-java@v2
        with:
          distribution: 'zulu'
          java-version: '11'
      - uses: subosito/flutter-action@v2
        with:
          flutter-version: '2.8.1'
      - name: Install dependencies
        run: flutter pub get
      - run: flutter test
Sami Issa
  • 1,695
  • 1
  • 18
  • 29
  • 1
    thanks man! that ssh setup was all I needed for finally getting my Github Action running again when using Swift Packages! – laka Jan 27 '23 at 17:01