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

Update github actions to allow forks run their own analysis in their own sonar cloud account (free for OSS) #120

Open
1 of 6 tasks
jordimontana82 opened this issue Nov 5, 2023 · 21 comments

Comments

@jordimontana82
Copy link
Contributor

jordimontana82 commented Nov 5, 2023

This is about updating GitHub actions to use repository_owner as opposed to the hardcoded DynamicsValue username. This would allow anyone to build their fork against their own SonarCloud account (which is free for Open Source repos).

This seems like a straight forward alternative compared to the hacks mentioned in #97 and it would make it easier to contribute while still using SonarCloud.

Thanks to @BetimBeja for this idea.

  • Abstractions
  • Core
  • Messages
  • Plugins
  • CodeActivities
  • Update Contributing guide in README
jordimontana82 added a commit to DynamicsValue/fake-xrm-easy-abstractions that referenced this issue Feb 4, 2024
jordimontana82 added a commit to DynamicsValue/fake-xrm-easy-abstractions that referenced this issue Feb 4, 2024
@jordimontana82
Copy link
Contributor Author

@BetimBeja

Several updates made to GitHub actions to support this.

It seems sonarcloud is expecting a lowercase organisation name. However there are no built-in expressions right now, so we had to use a workaround like this one: https://github.com/orgs/community/discussions/10553#discussioncomment-3776406

@jordimontana82
Copy link
Contributor Author

Try again, the merge was still running ?

@jordimontana82
Copy link
Contributor Author

jordimontana82 commented Feb 4, 2024

Is the sonarcloud org name the same as this one? For me it wouldn't work until the org name was set to lowercase... just curious cause the error you got is the same I got myself before that change.

image

@jordimontana82
Copy link
Contributor Author

It seems to me the org name needs to match the one in the url. It ran successfully after setting it to lowercase. Also maybe double check sonar token and/or project name?

image

@jordimontana82
Copy link
Contributor Author

jordimontana82 commented Feb 4, 2024

@BetimBeja if the sonar org value is different than your github repo owner it might be better to go for dedicated environment variables (ie. SONAR_ORG_NAME) and not use the github repo onwer (i.e. might be orgs where the sonar org name doesn't match their own GitHub's org name)?

@BetimBeja
Copy link

My sonar cloud org is different than my GitHub User Name 🤔
https://sonarcloud.io/organizations/betim-beja/projects

@jordimontana82
Copy link
Contributor Author

Aha! That makes sense so, I'll update the actions to use an environment variable instead :)

@jordimontana82
Copy link
Contributor Author

jordimontana82 commented Feb 4, 2024

That's merged into to the 2x-dev branch. Let me know if that works! :) @BetimBeja

https://github.com/DynamicsValue/fake-xrm-easy-abstractions/blob/2x-dev/.github/workflows/CI-PullRequest-2x.yml#L92

@BetimBeja
Copy link

@jordimontana82
I think I am a really edge case here 😢

image

I have renamed the repository when I forked it... so I think that the SONAR_PROJECT_PREFIX wont work properly

@jordimontana82
Copy link
Contributor Author

@BetimBeja if you delete the sonar project in your org and run a new analysis it should create a new one with the new key....

@BetimBeja
Copy link

It is what I was doing 😄

@BetimBeja
Copy link

@jordimontana82
Copy link
Contributor Author

jordimontana82 commented Feb 4, 2024

You need to add the 2 new github environment variables: they appear to be blank no?

https://github.com/BetimBeja/DynamicsValue_fake-xrm-easy-abstractions/actions/runs/7775451510/job/21201495227#step:10:79

These are the ones I have, so yours should match your sonarcloud settings, but they should work once there is a value there....

image

@BetimBeja
Copy link

Ok. I think I sorted the Sonar issue. I was using secrets instead of variables. And maybe I had some value copied wrong.

Now GitHub Packages...
https://github.com/BetimBeja/DynamicsValue_fake-xrm-easy-abstractions/actions/runs/7775451510/job/21201666062#step:10:118

@BetimBeja
Copy link

@jordimontana82 do you happen to have configured these two at organization level?
NUGET_USERNAME
NUGET_TOKEN

And I should do the same.

@jordimontana82
Copy link
Contributor Author

@BetimBeja
Copy link

https://github.com/BetimBeja/DynamicsValue_fake-xrm-easy-abstractions/blob/9442f46dac78211c744f026ed52a5b8c3a24dc92/.github/workflows/CI-2x.yml#L133 there are still some places where this is mapped to secrets.GITHUB_TOKEN instead of secrets.PACKAGES_TOKEN 😿

@jordimontana82
Copy link
Contributor Author

jordimontana82 commented Feb 4, 2024

They're different things:

PACKAGES_TOKEN is used to have read permissions to other repos for package restore (packing step) (i.e. core package needs read permission to restore the Abstractions package from GitHub packages)
GITHUB_TOKEN is the default one at the repo level to push packages into its own repo (push step)

So that CI github actions looks fine.

What error do you get now?

@jordimontana82
Copy link
Contributor Author

@BetimBeja packages token is a PAT you need to generate with only read packages permissions.

image

And you need to revisit the Actions sections in your repo (Settings -> Actions -> General) to give read / write permissions to the GITHUB_TOKEN (by default is read-only).

image

@BetimBeja
Copy link

Hey @jordimontana82,
I think I finally cracked this 😄
https://github.com/BetimBeja/DynamicsValue_fake-xrm-easy-abstractions/actions/runs/7790161781

the repo url was hardcoded to DynamicsValue and I switched to dotnet nuget push

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

No branches or pull requests

2 participants