github-actionsjqgithub-clinektos-act

Implement workflow to label Issue as "blocked" based on dependencies


I am trying to implement a GitHub Actions workflow that automatically labels an issue as "blocked" if it has dependencies on tasks that are still in progress. The action should be triggered when an issue is opened, edited, or reopened. Technical solution:

So far I have

I have tried different approaches related to GITHUB_TOKEN, secrets.GITHUB_TOKEN, etc., also I try to include the authentication directly in the steps where it's needed:

gh auth login --with-token ${{ secrets.GITHUB_TOKEN }}

But nothing that I have done can pass the GitHub CLI authentication withing Nektos/Act test tool.


Solution

  • It seems like your problem is only with authenticating when running the workflow locally. Per the act documentation:

    GITHUB_TOKEN

    GitHub automatically provides a GITHUB_TOKEN secret when running workflows inside GitHub.

    If your workflow depends on this token, you need to create a personal access token and pass it to act as a secret:

    act -s GITHUB_TOKEN=[insert token or leave blank and omit equals for secure input]
    

    If GitHub CLI is installed, the gh auth token command can be used to automatically pass the token to act

    act -s GITHUB_TOKEN="$(gh auth token)"
    

    WARNING: GITHUB_TOKEN will be logged in shell history if not inserted through secure input or (depending on your shell config) the command is prefixed with a whitespace.

    You're missing this -s parameter to provide valid token locally. Alternatively, if you have e.g. a .env file, you can use --secret-file, again per the docs:

    Secrets

    To run act with secrets, you can enter them interactively, supply them as environment variables or load them from a file. The following options are available for providing secrets:

    • act -s MY_SECRET=somevalue - use somevalue as the value for MY_SECRET.
    • act -s MY_SECRET - check for an environment variable named MY_SECRET and use it if it exists. If the environment variable is not defined, prompt the user for a value.
    • act --secret-file my.secrets - load secrets values from my.secrets file.
      • secrets file format is the same as .env format