nektos / act

Run your GitHub Actions locally 🚀
https://nektosact.com
MIT License
53.73k stars 1.34k forks source link

The `--local-repository`-argument does not work for reusable workflows #2390

Open weyert opened 1 month ago

weyert commented 1 month ago

Bug report info

act version:            0.2.64
GOOS:                   darwin
GOARCH:                 arm64
NumCPU:                 12
Docker host:            DOCKER_HOST environment variable is not set
Sockets found:
    /var/run/docker.sock
    $HOME/.docker/run/docker.sock
Config files:
    .actrc:
        -P ubuntu-latest=catthehacker/ubuntu:act-latest
        --container-architecture linux/amd64
        --env-file .env.local
        --secret-file .github.secrets.yml
        --var-file .github.vars.yml
        --artifact-server-path /tmp/artifacts
                --local-repository company-dev/devops-github-workflows=/Users/developer/Development/Projects/Company/devops-github-workflows

Build info:
    Go version:            go1.22.4
    Module path:           command-line-arguments
    Main version:
    Main path:
    Main checksum:
    Build settings:
        -buildmode:           exe
        -compiler:            gc
        -ldflags:             -X main.version=0.2.64
        DefaultGODEBUG:       httplaxcontentlength=1,httpmuxgo121=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1
        CGO_ENABLED:          1
        CGO_CFLAGS:
        CGO_CPPFLAGS:
        CGO_CXXFLAGS:
        CGO_LDFLAGS:
        GOARCH:               arm64
        GOOS:                 darwin
Docker Engine:
    Engine version:        26.1.4
    Engine runtime:        runc
    Cgroup version:        2
    Cgroup driver:         cgroupfs
    Storage driver:        overlay2
    Registry URI:          https://index.docker.io/v1/
    OS:                    OrbStack
    OS type:               linux
    OS version:
    OS arch:               aarch64
    OS kernel:             6.9.6-orbstack-00147-gb0567c7c0069
    OS CPU:                12
    OS memory:             7932 MB
    Security options:
        name=seccomp,profile=builtin
        name=cgroupns

Command used with act

act workflow_dispatch -W .github/workflows/experiment.yml

Describe issue

The problem I am having that when I pass the --local-repository it is not using the local copy of the repository but instead its using the remote repository instead. Making it difficult to develop and/or debug workflows.

Link to GitHub repository

No response

Workflow content

name: Build

on:
  workflow_dispatch:
  push:
    branches:
      - main

permissions: read-all

jobs:
  release:
    permissions:
      contents: write
      pull-requests: write

    uses: company-dev/devops-github-workflows/.github/workflows/validate.yml@main
    with:
      service_name: ${{ vars.SERVICE_NAME }}
      build_context: '.'
      build_file: 'true'
    secrets: inherit

Relevant log output

DEBU[0000] Handling container host and socket
DEBU[0000] Defaulting container socket to DOCKER_HOST
INFO[0000] Using docker host 'unix:///var/run/docker.sock', and daemon socket 'unix:///var/run/docker.sock'
DEBU[0000] Loading environment from /Users/developer/Development/Projects/Company/monorepo/.env.local
DEBU[0000] Loading action inputs from /Users/developer/Development/Projects/Company/monorepo/.input
DEBU[0000] Loading secrets from /Users/developer/Development/Projects/Company/monorepo/.github.secrets.yml
DEBU[0000] Conditional GET for notices etag=6a7d8901-3269-4f25-9332-46461cb761ca
DEBU[0000] Loading vars from /Users/developer/Development/Projects/Company/monorepo/.github.vars.yml
DEBU[0000] Evaluated matrix inclusions: map[]
DEBU[0000] Loading workflow '/Users/developer/Development/Projects/Company/monorepo/.github/workflows/remote.yml'
DEBU[0000] Reading workflow '/Users/developer/Development/Projects/Company/monorepo/.github/workflows/remote.yml'
DEBU[0000] Using first passed in arguments event for filtering: workflow_dispatch
DEBU[0000] Preparing plan for a event: workflow_dispatch
DEBU[0000] Using first passed in arguments event: workflow_dispatch
DEBU[0000] Planning jobs for event: workflow_dispatch
DEBU[0000] Artifacts base path '/tmp/artifacts'
INFO[0000] Start server on http://192.168.0.104:34567
DEBU[0000] gc: 2024-07-09 11:02:23.350949 +0000 UTC m=+0.037485126  module=artifactcache
DEBU[0000] Plan Stages: [0x14000494300]
DEBU[0000] Stages Runs: [release]
DEBU[0000] Job.Name: release
DEBU[0000] Job.RawNeeds: {0 0    <nil> []    0 0}
DEBU[0000] Job.RawRunsOn: {0 0    <nil> []    0 0}
DEBU[0000] Job.Env: {0 0    <nil> []    0 0}
DEBU[0000] Job.If: {0 0  success()  <nil> []    0 0}
DEBU[0000] Job.TimeoutMinutes:
DEBU[0000] Job.Services: map[]
DEBU[0000] Job.Strategy: <nil>
DEBU[0000] Job.RawContainer: {0 0    <nil> []    0 0}
DEBU[0000] Job.Defaults.Run.Shell:
DEBU[0000] Job.Defaults.Run.WorkingDirectory:
DEBU[0000] Job.Outputs: map[]
DEBU[0000] Job.Uses: company-dev/devops-github-workflows/.github/workflows/validate.yml@main
DEBU[0000] Job.With: map[build_context:. build_file:true service_name:${{ vars.SERVICE_NAME }}]
DEBU[0000] Job.Result:
DEBU[0000] Empty Strategy, matrixes=[map[]]
DEBU[0000] Job Matrices: [map[]]
DEBU[0000] Runner Matrices: map[]
DEBU[0000] Final matrix after applying user inclusions '[map[]]'
DEBU[0000] Loading revision from git directory
DEBU[0000] Found revision: 46d807fb4d869ff1bc0c5b686a9fee1bd9067844
DEBU[0000] HEAD points to '46d807fb4d869ff1bc0c5b686a9fee1bd9067844'
DEBU[0000] using github ref: refs/heads/wip/snoopy
DEBU[0000] Found revision: 46d807fb4d869ff1bc0c5b686a9fee1bd9067844
DEBU[0000] Detected CPUs: 12
[Build/release] [DEBUG] evaluating expression 'success()'
[Build/release] [DEBUG] expression 'success()' evaluated to 'true'
[Build/release] [DEBUG] Loading revision from git directory
[Build/release] [DEBUG] Found revision: 46d807fb4d869ff1bc0c5b686a9fee1bd9067844
[Build/release] [DEBUG] HEAD points to '46d807fb4d869ff1bc0c5b686a9fee1bd9067844'
[Build/release] [DEBUG] using github ref: refs/heads/wip/snoopy
[Build/release] [DEBUG] Found revision: 46d807fb4d869ff1bc0c5b686a9fee1bd9067844
Error: EOF

Additional information

Masked some project specific details

ChristopherHX commented 1 month ago

I assume your problem here is the missing tagname before the =

Maybe try

--local-repository company-dev/devops-github-workflows@main=/Users/developer/Development/Projects/Company/devops-github-workflows

Supporting this without tag name e.g. any ref might be a useful addition tbd.

Didn't test it again, I'm busy with other tasks

weyert commented 1 month ago

have tried your suggestion but it is not working. Do you know where in the code this parameter is used? I don't see any (verbose) logs about it copying or mapping this repository somehow.

I do wonder if the problem is that I try to reference a particular workflow, e.g. company-dev/devops-github-workflows.github/workflows/validate.yml@main instead of company-dev/devops-github-workflows@main

ChristopherHX commented 1 month ago

I don't have enough information to locate a problem in the code, maybe I need to check macOS (using ubuntu 24.04) or you have typos

The following error is expected if you run act -W w.yml in folder main here a zip (act-use-workflow.zip)

INFO[0000] Using docker host 'unix:///var/run/docker.sock', and daemon socket 'unix:///var/run/docker.sock' 
WARN[0000] unable to get git repo (githubInstance: github.com; remoteName: origin, repoPath: /home/user/act-use-workflow/main): repository does not exist 
ERRO[0000] path/home/user/act-use-workflow/mainnot located inside a git repository  error="repository does not exist"
WARN[0000] unable to get git ref: repository does not exist 
ERRO[0000] path/home/user/act-use-workflow/mainnot located inside a git repository  error="repository does not exist"
WARN[0000] unable to get git revision: repository does not exist 
[w.yml/reusable] unable to get git repo (githubInstance: github.com; remoteName: origin, repoPath: /home/user/act-use-workflow/main): repository does not exist
[w.yml/reusable] path/home/user/act-use-workflow/mainnot located inside a git repository
[w.yml/reusable] unable to get git ref: repository does not exist
[w.yml/reusable] path/home/user/act-use-workflow/mainnot located inside a git repository
[w.yml/reusable] unable to get git revision: repository does not exist
Error: lstat /home/user/act-use-workflow/re/.github/workflows/test.yml: no such file or directory

Empty workflow file

Error: unable to read workflow 'test.yml': file is empty: EOF

If it is valid it continues for me......

Do you know where in the code this parameter is used?

Maybe I was very sparing when logging, here this code matches

https://github.com/nektos/act/blob/3c7eda7f3ea9ce6fe7358a802b19474b9d207447/pkg/runner/local_repository_cache.go#L24-L91

  1. Case sensitive, differen case pull from GitHub
  2. omit @<version> will never match anything

I suggest making a breakpoint in the fetch method and look why it skipped

weyert commented 1 month ago

Thank you! I am having a look.

Struggling a bit to get the code compiled while also having act installed via Homebrew. Once I cracked that problem I will get some breakpoints going.

weyert commented 1 month ago

Looks like your suggestion works @ChristopherHX . The only time it appears to go wrong when you try to use it together with a matrix strategy then a concurrent write error occurs. Don’t think that’s a big problem, though

ChristopherHX commented 3 weeks ago

@weyert

Looks like your suggestion works @ChristopherHX . The only time it appears to go wrong when you try to use it together with a matrix strategy then a concurrent write error occurs. Don’t think that’s a big problem, though

Are you able to provide an minimal reproducible repo with Error: EOF

I tried

Doesn't seem your problem description let me debug the problem in your original post.

weyert commented 3 weeks ago

@ChristopherHX Yeah, I will take some time this week to try to make a reproducible case.