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

Release of jenkins-contribution-* GO applications fail: homebrew token not found #4141

Closed
jmMeessen opened this issue Jun 14, 2024 · 16 comments
Assignees
Labels

Comments

@jmMeessen
Copy link

Service(s)

GitHub

Summary

The GoReleaser based release process updates a repository (jenkins-infra/homebrew) to make the new release available via HomeBrew. With the migration of the tools from "jmMeessen" to "jenkins-infra" this process doesn't work anymore.

The error message is

Error: Could not create installation access token.
(...)
  [cause]: Error: Could not retrieve installation.
(...)
    [cause]: RequestError [HttpError]: Not Found

This process is handled by the "release" GitHub action. It sets up on-the-fly a token via a GitHub app to allow the GHA to update another repository in the Org (the "homebrew" repository) via a commit. In this case, the failure comes the local secrets to access the app are not set.

This is the code where the token is generated (release.yml#L19-24):

    - uses: tibdex/github-app-token@v2
      id: generate_homebrew_token
      with:
        app_id: ${{ secrets.HOMEBREW_APP_ID }}
        private_key: ${{ secrets.HOMEBREW_APP_PRIVKEY }}

and this is how the token is retrieved and used in the release step (release.yml#L24-L31):

    - name: Release via goreleaser
      uses: goreleaser/goreleaser-action@v5
      with:
        distribution: goreleaser
        args: release
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        HOMEBREW: ${{ steps.generate_homebrew_token.outputs.token }}

As far as I remember, the solution is to install an application that has update/commit access in jenkins-infra/homebrew repository and to add the APP_ID and the APP_PRIVKEY as secrets in the repository.

Reproduction steps

No response

@lemeurherve
Copy link
Member

For reference, from #4017 (comment):

[...] the first two repositories have to be configured to let goreleaser publishings corresponding taps to https://github.com/jenkins-infra/homebrew-tap.

Like what's done in https://github.com/jenkins-infra/jenkins-version/blob/1342d2771b99c6de6afee408d4b1916c1555cab3/.goreleaser.yml#L63-L76.

@jmMeessen
Copy link
Author

I tried it out the suggested method , expecting the GITHUB_TOKEN of jenkins-infra to have some unusual magic. And it didn't work.

Looking closely at the GitHub action used by jenkins-version, I can demonstrate that it uses the GH App technique and Tibdex/github-app-token the same way as my program did.

      - uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2
        id: generate-token
        with:
          app_id: ${{ secrets.JENKINS_ADMIN_APP_ID }}
          private_key: ${{ secrets.JENKINS_ADMIN_APP_PRIVKEY }}

https://github.com/jenkins-infra/jenkins-version/blob/1342d2771b99c6de6afee408d4b1916c1555cab3/.github/workflows/release.yaml#L54C1-L58C64

The only difference is that instead of loading the temporary token in HOMEBREW (obvious name IMHO), the designer of jenkins-version loads it in GITHUB-TOKEN.

@lemeurherve maybe the used secrets name are a hint to what GH App to use (JENKINS_ADMIN_APP).

I am restoring my original code.

@jmMeessen
Copy link
Author

Any news about the planning of this issue @lemeurherve? I see that it is still in triage. This is blocking the transfer of the system and I have only 6 days left (and other issues to solve).

If it can help, I can help you by explaining how it works (I implemented it with three applications) although I have only limited access to the jenkins-infra org. I believe that the application to install and configure in the two migrated application is JENKINS_ADMIN_APP.

@dduportal
Copy link
Contributor

Any news about the planning of this issue @lemeurherve? I see that it is still in triage. This is blocking the transfer of the system and I have only 6 days left (and other issues to solve).

If it can help, I can help you by explaining how it works (I implemented it with three applications) although I have only limited access to the jenkins-infra org. I believe that the application to install and configure in the two migrated application is JENKINS_ADMIN_APP.

For info, the jenkins-infra team is doing triage every Tuesday during the weekly meeting (except for "level 1" support requests or production issue of course): this issue will be triaged later today and most probably be part of the upcoming milestone since worked already started.

@jmMeessen Just to be sure (as I'm only starting to check this topic while preparing the weekly meeting): can you confirm the migrated repository is specifying the existing https://github.com/jenkins-infra/homebrew-tap (and not https://github.com/jenkins-infra/homebrew which does not exist)?

Another point: I confirm that @jmMeessen said that a GH Application is required for the homebrew release to the tap as the Github Action GITHUB_TOKEN is always scoped to the repository where it runs. We need to set up one / reuse eventually existing one with permissions to https://github.com/jenkins-infra/homebrew-tap and insert the 2 credentials in the migrated repositories.

@jmMeessen
Copy link
Author

jmMeessen commented Jun 18, 2024 via email

@dduportal dduportal removed the triage Incoming issues that need review label Jun 18, 2024
@dduportal dduportal added this to the infra-team-sync-2024-06-25 milestone Jun 18, 2024
@dduportal
Copy link
Contributor

triaged: Related to #4017 , added to milestone, taken by @lemeurherve

@dduportal
Copy link
Contributor

Did a quick check on the existing jenkins-infra/homebrew-tap repository. It was used by jenkins-infra/uc (now archived) and jenkins-infra/jenkins-version.

I understand that the GitHub applications we used to use are old and were misunderstood (by us) in the past: the scoped both updatecli, homebrew tap, binary releases inside GHAs which is too vast.

@lemeurherve a few pointers to unblock this issue quickly:

Note about goreleaser: as per https://goreleaser.com/ci/actions/#token-permissions, we can only provide one GH token to goreleaser. Since it manages publication in the repo where it runs (GH release binaries, tag pushing, etc.) AND homebrew-tap in another repository, it means we cannot have a GH application only for homebrew: its scope is wider for goreleaser.

@lemeurherve
Copy link
Member

New "goreleaser in jenkins-infra" GitHub App created (App ID: 925062), with "Contents: Read & Write" permissions, installed on selected repositories (https://github.com/jenkins-infra/jenkins-version & https://github.com/jenkins-infra/jenkins-contribution-extractor).

Tested this new GitHub App on jenkins-version (jenkins-infra/jenkins-version#201) with success:
jenkins-infra/homebrew-tap@4499c9d

Opening a pull request on https://github.com/jenkins-infra/jenkins-contribution-extractor to use this new GitHub App credentials.

@lemeurherve
Copy link
Member

@lemeurherve
Copy link
Member

Retrigered the last failed goreleaser job https://github.com/jenkins-infra/jenkins-contribution-extractor/actions/runs/9548130664, got the following error:

⨯ release failed after 8s error=1 error occurred:

Currently looking at what's wrong.

@lemeurherve
Copy link
Member

As I rerun the job, it used the same commit, thus it didn't include the new credentials.

Created a new release to trigger goreleaser which worked as expected:

Closing this issue as resolved, thanks @dduportal for the help!

@dduportal
Copy link
Contributor

Reopening until @jmMeessen can confirm (most probably Thursday) that it is good for him

@dduportal dduportal reopened this Jun 19, 2024
@lemeurherve lemeurherve changed the title Release of jenkins-ccontributor-* GO applications fail: homebrew token not found Release of jenkins-contribution-* GO applications fail: homebrew token not found Jun 19, 2024
@lemeurherve
Copy link
Member

lemeurherve commented Jun 19, 2024

While doing this in pair we forgot to do the same than #4141 (comment) for the second Go repository https://github.com/jenkins-infra/jenkins-contribution-aggregator.

Taking care of it.

@lemeurherve
Copy link
Member

Installed the "goreleaser in jenkins-infra" GitHub App to https://github.com/jenkins-infra/jenkins-contribution-aggregator and opened jenkins-infra/jenkins-contribution-aggregator#40 to use its credentials.

Also removed the remnant HOMEBREW_APP_ID and HOMEBREW_APP_PRIVKEY repository secrets from these two Go repositories as they aren't used anymore.

@jmMeessen
Copy link
Author

I confirm that (for both repositories)

  • the trigger of a release works with the access rights of a maintainer (defining and pushing a tag to the main branch of the repository)
  • the automatic HomeBrew tap update works with the GitHub Action
  • the new executables can be installed locally (or in a container) with the brew install command.

This issue/task can be considered as completed.

I thank all those who participated to make this possible. It was critical seen the severe time constrain we had to complete and stabilise the migration in the short time left.

@gounthar
Copy link

Thanks a lot to all the people that were involved in that migration. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants