[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to work with local actions outside of the repository we run the workflows from #1579

Open
Porkepix opened this issue Jan 23, 2023 · 17 comments
Labels
kind/feature-request New feature or request

Comments

@Porkepix
Copy link

Act version

act version 0.2.34

Feature description

It would be a nice feature, when developing a new action or more, several actions (for example to migrate from CircleCI's orbs to GitHub's actions) to be able to have like a "path" (I mean, the same way you'd add a location to your $PATH for your shell) act would be looking at/mounting, so that when fetching actions it could also get them from here, to allow for actions development offline and not only the workflows themselves.

Note that I might have missed the way to do so, but the best I could find was to copy and paste actions within the repo itself and change to call from the org/repo syntax to a local one

@Porkepix Porkepix added the kind/feature-request New feature or request label Jan 23, 2023
@trash-anger
Copy link

I was about to create quite a similar feature request!

I'm working in a company which have quite a flexible remote work policy leading developers to travel a lot by flight. (which is currently my case)

I'm a new user of act and when I tried to use act during my previous flight I just got this message:
FATA[0000] dial udp 8.8.8.8:80: connect: network is unreachable

So landing I've been wondering how we could work offline an easy way, it could be nice to implement a caching solution allowing to fetch pipeline dependencies while running it. Then running it again would first try to reach online first (and update the cache as a result) and offline, would rely on the cache.

I'm currently adapting the pipelines of my company to get a custom behaviour depending on the GITHUB_ACTIONS var to allow anyone to build locally, and deploy the current component to a local k8s cluster.

I'm thinking out loud:

Another interesting thing would be to implement a similar feature than the ".github" repository. I haven't check if it's possible to make it work with a simlink added to the gitignore tho.

@Porkepix , maybe you could use the workflow reuse function if it works and if you can refactor your pipeline.

@Porkepix
Copy link
Author

I was about to create quite a similar feature request!

I'm working in a company which have quite a flexible remote work policy leading developers to travel a lot by flight. (which is currently my case)

I'm a new user of act and when I tried to use act during my previous flight I just got this message: FATA[0000] dial udp 8.8.8.8:80: connect: network is unreachable

So landing I've been wondering how we could work offline an easy way, it could be nice to implement a caching solution allowing to fetch pipeline dependencies while running it. Then running it again would first try to reach online first (and update the cache as a result) and offline, would rely on the cache.

Act actually already cache actions, see ~/.cache/act. The issue here is rather that it tries to reach out Google's Public DNS which is curious to say the least. I noticed it too but didn't opened an issue, would definitely be interesting to know why it does that. And if every resources are available locally then, yes, I believe it should work 100% offline.

What I had in mind was rather to have a clone of the actions repos and to provide them to act like you would with libs given to a compiler, or bineries in your $PATH: a local place to look for those actions.

@Porkepix , maybe you could use the workflow reuse function if it works and if you can refactor your pipeline.

I don't understand what you had in mind here.

@ChristopherHX
Copy link
Contributor

@trash-anger Please create a new issue about FATA[0000] dial udp 8.8.8.8:80: connect: network is unreachable

This function should just return 127.0.0.1 on a network error and the artifact server might not work correctly.

log.Fatal(err)

@trash-anger
Copy link

I'm boarding, I'll do that tonight!

@cardinalby
Copy link

Act is great for testing Workflows. Developing individual actions I also tried to use act, but found that it's better to have integration tests. Especially for JavaScript actions where you can run your action locally offline, pass intputs, env, etc. and debug it, test its outputs, examine all commands issued by the action, etc.

I use github-action-ts-run-api for that.

@mcascone
Copy link
mcascone commented Jun 2, 2023

All I want is to be able to develop my actions locally, separate from the repo with the workflow file that calls them.

Specifically, I want to be able to use a local path in the uses: part of a workflow:

Existing behavior

jobs:
  Deploy:
    steps:
      - uses: 'myOrg/my-action@my-branch'

Desired functionality

jobs:
  Deploy:
    steps:
      - uses: '/path/to/local/my-action@my-branch'

Going by the output, there would need to be a trigger or flag to not tack the https://github.com onto the path:

 git clone 'https://github.com/~/myOrg' # ref=my-branch
[My-Action/Deploy] Unable to clone https://github.com/~/myOrg refs/heads/my-branch: repository not found

@mverkerk-godaddy
Copy link

I'm struggling with this too - I'm building a library of actions that can be shared across repos within our github org and when I'm testing this library locally with ACT, the uses: pieces should point to .[/path] where otherwise, they should point to {org}/{repo}[/path]@ref ...

Currently, I have to (temporarily) update everything from {org}/{repo}[/path]@ref to .[/path], run ACT, and change everything back before I commit/push (easy to forget). I have written a bash script that takes care of this but that's not ideal. I'll include the script at the bottom of this message...

In my testing, I have tried setting an ENV variable and/or using env.ACT but unfortunately uses: does not support variables (as far as I know)

This example:

- uses: ${{ env.ACT && './.github/actions/my-action' || 'org/repo/.github/actions/my-action@main' }}
  with:
    some-input: input

... failed with this error:

Error: Expected format {org}/{repo}[/path]@ref. Actual '${{ env.ACT && './.github/actions/my-action' || 'my-org/my-repo/.github/actions/my-action@main' }}' Input string was not in a correct format

would be great if there was a flag like --replace-ghe-path-with-local {org}/{repo} that would make this switch for us!

btw: thanks for all the great work! really enjoying this tool! 👍🏼

Here's my act_path_replace.sh script:

#!/usr/bin/env bash
target=${1}

if [ "$target" == "--to-remote" ]; then
  echo "Updating [action.yml] files to point to [org/repo/.github/actions]"
  FILES=$(find . -name "action.yml" -type f -exec grep -l "uses:.*\.\/\.github\/actions\/" {} \;)
  for file in $FILES; do
    sed -i 's|./.github/actions|org/repo/.github/actions|g' "$file"
    sed -i '/uses:.*\.github\/actions\//!b;/@v2/b;s/$/@v2/' "$file"
  done
elif [ "$target" == "--to-local" ]; then
  echo "Updating [action.yml] files to point to [./.github/actions]"
  FILES=$(find . -name "action.yml" -type f -exec grep -l "uses:.*org\/repo\/\.github\/actions\/" {} \;)
  for file in $FILES; do
    sed -i 's|org/repo|.|g' "$file"
    sed -i 's|@v2$||g' "$file"
  done
else
  echo "Please specify a target: local or remote"
  exit 1
fi

@ChristopherHX
Copy link
Contributor
ChristopherHX commented Aug 16, 2023

Please test this version of act ChristopherHX#34.

Usage: ./act --local-repository "https://github.com/test/test@v0=$PWD" -W test.yml -P self-hosted=-self-hosted -v

on: push
jobs:
  _:
    runs-on: self-hosted
    steps:
    - uses: test/test@v0

action.yml in cwd

runs:
  using: composite
  steps:
  - run: echo Test

I need reviewer for #1954, because --local-repository is based on that code.

@reneleonhardt
Copy link

Please test this version of act ChristopherHX#34.

Why was it closed after #1954 has been merged? 🤔

@ChristopherHX
Copy link
Contributor

Why was it closed after #1954 has been merged? 🤔

Summary It was the wrong target repository and was used to keep it via GitHub UI uptodate.

Actually this has been merged by now, see act --help.

Since nobody has ever commented between our comments, I forget this issue exists. Please evaluate if this can be closed

@mcascone
Copy link
mcascone commented May 1, 2024

is there any documentation on this other than the help text?

 --local-repository stringArray                      

Replaces the specified repository and ref with a local folder 

e.g. https://github.com/test/test@v0=/home/act/test or test/test@v0=/home/act/test, 
the latter matches any hosts or protocols

@ChristopherHX
Copy link
Contributor

Some more details here: #2155 (comment)

Usage: ./act --local-repository "https://github.com/test/test@v0=$PWD" -W test.yml -P self-hosted=-self-hosted -v

Now also possible ./act --local-repository "test/test@v0=$PWD" -W test.yml -P self-hosted=-self-hosted -v

on: push
jobs:
  _:
    runs-on: self-hosted
    steps:
    - uses: test/test@v0

action.yml in cwd

runs:
  using: composite
  steps:
  - run: echo Test

@reneleonhardt
Copy link

@Porkepix Is your use case now possible?

I can't see from this --local-repository example if mcascone's intuitive feature request #1579 (comment) works when replacing $PWD by the actual absolute path to the local test/test repo... if it's outside of $PWD 😅

@ChristopherHX
Copy link
Contributor

mcascone's intuitive feature request

That won't work and I don't agree with accepting yaml that GitHub Actions doesn't like to see. You would need to find someone else supporting such an idea, I'm not an owner of this project.

You should make shure it's an absolute path. If it's relative, I guarantee nothing and it could just fail.
E.g. $PWD is really just a bash variable for an absolute path, there are no sanity checks

This is what you should be able to get working based on the referenced comment

jobs:
  Deploy:
    steps:
      - uses: 'myOrg/my-action@my-branch'

act --local-repository myOrg/my-action@my-branch=/path/to/local/my-action and /path/to/local/my-action is created by git clone myOrg/my-action -b my-branch my-action within /path/to/local/. So /path/to/local/my-action contains the .git dir and it's action.yml file.

Feel free to come back to me with any error, --local-repository is an feature flag it implies changing how actions are cloned

If you want to apply this automatically without adding the arg everytime create a ./.actrc file like (don't use any ", as this just do a split on the first space)

--local-repository myOrg/my-action@my-branch=/path/to/local/my-action

You might be using this Software more often than I, even if I contributed more code

@ChristopherHX
Copy link
Contributor
ChristopherHX commented May 6, 2024

The error messages if the folder/file doesn't exist are bad and only the myOrg/my-action@my-branch part shows up together with the tried file names

This is what I mean, maybe it makes sense to log more about the hidden source of the action, the default implied by --local-repository is also to use bare git clones of actions.

Error: failed to read 'action.yml' from action 'myOrg/my-action@my-branch' with path '' of step file does not exist
failed to read 'action.yaml' from action 'myOrg/my-action@my-branch' with path '' of step file does not exist
failed to read 'Dockerfile' from action 'myOrg/my-action@my-branch' with path '' of step file does not exist

To be honest using act might be really complicated by now with all it's cli flags and weird error messages

@jsoref
Copy link
Contributor
jsoref commented Nov 4, 2024

I was going to file a new issue for https://github.com/check-spelling-sandbox/nektos-act-issue-up-dir/actions/runs/11671555945 not working in act, but this issue technically is the right issue.

Summary:

  1. The GitHub Actions Runtime does allow paths outside the checkout directory, specifically using a syntax of ./../ (and presumably more than that, but whatever).
  2. github/codeql-action heavily uses this feature.
  3. For check-spelling, instead of using that feature (because I didn't find it), I'm leaving my action shims within .git/, but it would be much cleaner if I could leave them in ./../ instead.

.github/workflows/test.yml:

on:
  push:
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - run: |
        mkdir ../action
        mv * ../action
    - uses: ./../action

action.yml

runs:
  using: node20
  main: main.js

main.js

console.log("hello world")

GitHub

Run mkdir ../action
Run ./../action
hello world

Act

[test.yml/test] ⭐ Run Main actions/checkout@v4
[test.yml/test]   🐳  docker cp src=/Users/jsoref/code/nektos/issues/up-dir/. dst=/Users/jsoref/code/nektos/issues/up-dir
[test.yml/test]   ✅  Success - Main actions/checkout@v4
[test.yml/test] ⭐ Run Main mkdir ../action
mv * ../action
[test.yml/test]   🐳  docker exec cmd=[bash -e /var/run/act/workflow/1] user= workdir=
[test.yml/test]   ✅  Success - Main mkdir ../action
mv * ../action
[test.yml/test] ⭐ Run Main ./../action
[test.yml/test]   ❌  Failure - Main ./../action
[test.yml/test] failed to read 'action.yml' from action './../action' with path '' of step file does not exist
failed to read 'action.yaml' from action './../action' with path '' of step file does not exist
failed to read 'Dockerfile' from action './../action' with path '' of step file does not exist
[test.yml/test] 🏁  Job failed
Error: Job 'test' failed

@ChristopherHX
Copy link
Contributor

You mean this: #2108 that has an dedicated issue for this.

I refused to give my approval (+0/neutral), but I wouldn't block it if I'm overvoted by maintainers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

8 participants