GithubHelp home page GithubHelp logo

Comments (8)

LecrisUT avatar LecrisUT commented on May 22, 2024 2

I don't think that is equivalent, e.g. how can we make the github actions testable, especially for forks.

from typescript-action.

ncalteen avatar ncalteen commented on May 22, 2024

Hello!

Apologies for the delay in responding to this issue. Currently, referencing the action locally will not let the pre step run. However, as a workaround, you can reference the local action by specifying the repository and path. For example, if your repository contains an action that looks like the following (index.js is the main script and setup.js is the pre script):

my-action
├── action.yml
├── index.js
├── package-lock.json
├── package.json
└── setup.js

You could reference the action in a workflow file like this:

jobs:
  run:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      - uses: <owner>/<repo>/my-action@main

This should let pre script run as expected!

from typescript-action.

nwalters512 avatar nwalters512 commented on May 22, 2024

This workaround makes it impossible to test changes to an action in the repo in which it's developed, which I imagine is a very common use case for folks who are writing and referencing local actions. It'd work if one could write - uses: <owner>/<repo>/my-action@${{ github.sha }}, but that's not allowable.

Can someone from GitHub explain why pre: and friends aren't supported for local actions?

from typescript-action.

ncalteen avatar ncalteen commented on May 22, 2024

I did some checking internally to see why pre is not supported for local actions. The reason is because the action itself is downloaded and run after the job starts and any pre steps have run. On the other hand, post does work when referencing local actions.

As far as testing the action, you should be able to reference either your fork repo or branch name without issue:

- uses: <owner>/<fork-repo>@main
- uses: <owner>/<action-repo>@<feature-branch>

Are there specific errors you're running into when testing actions in a fork or branch? I'd be happy to dig into it if you have a reproducible example

from typescript-action.

ncalteen avatar ncalteen commented on May 22, 2024

Closing due to lack of activity. If you'd like to revisit this please open a new issue and provide any additional details that may be useful :)

from typescript-action.

LecrisUT avatar LecrisUT commented on May 22, 2024

There is no activity because the request is clear. We need it for relative path. That's the form that works for gh actions to allow PRs, otherwise whenever a new PR is made, they need to point the unit tests to their fork, run the tests and point them back to the original repo before merging

from typescript-action.

ncalteen avatar ncalteen commented on May 22, 2024

Apologies! I misunderstood the request :/

I was able to find more info here. In particular:

Action referenced from local repository (./my-action) won't get pre setup correctly since the repository haven't checked-out during job initialization. We can't use GitHub api to download the repository since there is about a 3 minute delay between git push and the new commit available to download using GitHub api.

As far as current workarounds, yes you can fork the action repo, update the workflow to reference the forked repo name, and then update to the original repo name before submitting the PR.

Another option would be to convert to a composite action and move the pre/post steps into the "actual" workflow steps. E.g. instead of this:

runs:
  using: 'node12'
  pre: 'lib/setup.js'
  main: 'lib/main.js'
  1. Convert the pre step to it's own action

    name: Setup Pre Action
    description: Setup Pre Action
    
    runs:
      using: node20
      main: ../lib/pre.js
  2. Convert the main step to a separate action

    name: Main Action
    description: Main Action
    
    runs:
      using: node20
      main: ../lib/index.js
  3. Call both actions in a composite

    name: Composite Action
    description: A composite action for demo purposes
    
    runs:
      using: composite
      steps:
        # This was previously a `pre` step in a Node.js action
        - name: Setup
          uses: ./setup-action
    
        # This was previously a `main` step in a Node.js action
        - name: Main
          uses: ./main-action

I created a trivial reproduction here if that helps. The benefit there is you shouldn't need to rename anything when forking and making updates.

from typescript-action.

LecrisUT avatar LecrisUT commented on May 22, 2024

We can't use GitHub api to download the repository since there is about a 3 minute delay between git push and the new commit available to download using GitHub api.

Sorry, but this sounds luke bs on their side. Why can't the pre be delayed for after git checkout, and why would the delay not have a similar effect on the repo reference approach?

Another option would be to convert to a composite action and move the pre/post steps into the "actual" workflow steps

That is the approach I've converged to, but I don't like it because it wraps all of the stdout to composite-like output.

from typescript-action.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.