'Github Action won't run until manually enabled

I need to create a bunch of repositories programmatically using from a local template. I have a .github/workflows/build.yml with on: [push]. However, Github Action won't run, even if I wait for several minutes after repo creation or commit and push several commits.

If I go to Actions tab, I see this:

enter image description here

If I click on Enable Actions on this repository, tab changes to this:

enter image description here

And if I make a push after this - Action works, without any changes to build.yml. Is this expected behavior?

If yes, how can I automate this? There doesn't seem any corresponding endpoint in Actions API



Solution 1:[1]

This is expected behaviour.

You can use e.g. the REST API to activate GitHub actions for a repository. Replace OWNER and REPO with the values to specify the repository. Replace USERNAME and TOKEN with the details of your personal access token (PAT).

You must authenticate using an access token with the repo scope to use this endpoint.

curl \
  -X PUT \
  -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/OWNER/REPO/actions/permissions \
  -d '{"enabled":true,"allowed_actions":"all"}'
  -u USERNAME:TOKEN

Source: https://docs.github.com/en/rest/reference/actions#set-github-actions-permissions-for-a-repository

Solution 2:[2]

Well, since it appears that no API call can be used to enable Actions in organization repository, I had to resort to Selenium and automate clicking :\

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 riQQ
Solution 2 Amomum