# GitHub Action<no value>
// <!-- Required for asciidoctor -->
:toc:
// Set toclevels to be at least your hugo [markup.tableOfContents.endLevel] config key
:toclevels: 4

== Description

Updatecli is most effective when executed regularly and automatically. So, lets see how to use updatecli in a GitHub Action.

== Credentials

Updatecli requires a token to interact with the GitHub API. It can be done using different approaches.

**GITHUB_TOKEN**

The easiest one is the GITHUB_TOKEN which comes with two major limitations:

1. For security reason, GitHub prevents to trigger GitHub action workflow from pullrequest created with a GITHUB_TOKEN, more information https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/trigger-a-workflow#triggering-a-workflow-from-a-workflow[**here**]. This means that a pullrequest recreated this way won't trigger any test.
2. GITHUB_TOKEN has the lower API request limit 1000 requests per hour as explained https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#primary-rate-limit-for-github_token-in-github-actions[**here**]

IMPORTANT: By default the GITHUB_TOKEN is not allowed to open pullrequest. You first need to configure the default GITHUB_TOKEN permission for your repository. More information https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository#preventing-github-actions-from-creating-or-approving-pull-requests[**here**]

**Personal Access Token**

The second approach is to configure a GitHub action secret with a personal access token that allow 5000 request per hour https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#primary-rate-limit-for-authenticated-users[**src**].

**GitHub App**

The third approach is to use a GitHub App that provides the highest api limit, 15000 request per hour https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/trigger-a-workflow#triggering-a-workflow-from-a-workflow[**here**].

**Conclusion**

The third option is the best one but not yet supported natively by Updatecli. An issue is open at https://github.com/updatecli/updatecli/issues/2262[**issue#2262**]. A workaround is available by using the GitHub action https://github.com/actions/create-github-app-token[**actions/create-github-app-token**].

== Migration

=== From V1 to v2

The updatecli action v1 was a "GitHub Action" of type docker. While it was easier to start with, that type of GitHub Action runs in a docker container and so in a fully isolated environment.
Updatecli uses many other tools. So switching to a Javascript GitHub action, allows installing updatecli directly on the GitHub Action runner next to those other tools.
Now, the goal of this GitHub action evolved from running updatecli to installing updatecli.

== Parameter

=== Version
`version`: specifies the Updatecli version to install. Accepted values are any valid releases such as `v0.25.0`.
The default value corresponds to the latest Updatecli version

Required: false

== Example

The current example takes uses the repository https://github.com/jenkins-infra/jenkins-infra[jenkins-infra/jenkins-infra].

Once you have your update strategy configuration in the directory `./updatecli/updatecli.d`, you need following files in order to run updatecli from Github Action.

**./updatecli/values.yaml**
```
{{< include "assets/code_example/docs/automate/github_action/values.yaml" >}}
```

**./github/workflows/updatecli.yaml**
```
{{< include "assets/code_example/docs/automate/github_action/updatecli.yaml" >}}
```

IMPORTANT: Environment variables starting with `GITHUB_` are reserved by GitHub Actions.
