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

[workflows] Fix permissions check for creating new releases #81163

Merged
merged 3 commits into from
Feb 21, 2024

Conversation

tstellar
Copy link
Collaborator

@tstellar tstellar commented Feb 8, 2024

The default GitHub token does not have read permissions on the org, so we need to use a custom token in order to read the members of the llvm-release-managers team.

The default GitHub token does not have read permissions on the org, so
we need to use a custom token in order to read the members of the
llvm-release-managers team.
@llvmbot
Copy link

llvmbot commented Feb 8, 2024

@llvm/pr-subscribers-github-workflow

Author: Tom Stellard (tstellar)

Changes

The default GitHub token does not have read permissions on the org, so we need to use a custom token in order to read the members of the llvm-release-managers team.


Full diff: https://github.com/llvm/llvm-project/pull/81163.diff

2 Files Affected:

  • (modified) .github/workflows/release-tasks.yml (+3-1)
  • (modified) llvm/utils/release/github-upload-release.py (+7-4)
diff --git a/.github/workflows/release-tasks.yml b/.github/workflows/release-tasks.yml
index f2a831ad3577ad..53da8662b0203a 100644
--- a/.github/workflows/release-tasks.yml
+++ b/.github/workflows/release-tasks.yml
@@ -28,6 +28,7 @@ jobs:
     name: Create a New Release
     runs-on: ubuntu-latest
     needs: validate-tag
+
     steps:
       - name: Install Dependencies
         run: |
@@ -40,8 +41,9 @@ jobs:
       - name: Create Release
         env:
           GITHUB_TOKEN: ${{ github.token }}
+          USER_TOKEN: ${{ secrets.RELEASE_TASKS_USER_TOKEN }}
         run: |
-          ./llvm/utils/release/./github-upload-release.py --token "$GITHUB_TOKEN" --release ${{ needs.validate-tag.outputs.release-version }} --user ${{ github.actor }} create
+          ./llvm/utils/release/./github-upload-release.py --token "$GITHUB_TOKEN" --release ${{ needs.validate-tag.outputs.release-version }} --user ${{ github.actor }} --user-token "$USER_TOKEN" create
   release-documentation:
     name: Build and Upload Release Documentation
     needs:
diff --git a/llvm/utils/release/github-upload-release.py b/llvm/utils/release/github-upload-release.py
index a8bb569d2fc999..5115e5082fb2c1 100755
--- a/llvm/utils/release/github-upload-release.py
+++ b/llvm/utils/release/github-upload-release.py
@@ -77,20 +77,23 @@ def upload_files(repo, release, files):
 parser.add_argument("--token", type=str)
 parser.add_argument("--release", type=str)
 parser.add_argument("--user", type=str)
+parser.add_argument("--user-token", type=str)
 
 # Upload args
 parser.add_argument("--files", nargs="+", type=str)
 
 args = parser.parse_args()
 
-github = github.Github(args.token)
-llvm_org = github.get_organization("llvm")
+gh = github.Github(args.token)
+llvm_org = gh.get_organization("llvm")
 llvm_repo = llvm_org.get_repo("llvm-project")
+if not args.user_token:
+    args.user_token = args.token
 
 if args.user:
     # Validate that this user is allowed to modify releases.
-    user = github.get_user(args.user)
-    team = llvm_org.get_team_by_slug("llvm-release-managers")
+    user = gh.get_user(args.user)
+    team = github.Github(args.user_token).get_organization("llvm").get_team_by_slug("llvm-release-managers")
     if not team.has_in_members(user):
         print("User {} is not a allowed to modify releases".format(args.user))
         sys.exit(1)

Copy link

github-actions bot commented Feb 8, 2024

✅ With the latest revision this PR passed the Python code formatter.

Copy link
Contributor

@boomanaiden154 boomanaiden154 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor comment from me.

llvm/utils/release/github-upload-release.py Outdated Show resolved Hide resolved
Copy link
Contributor

@boomanaiden154 boomanaiden154 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@tstellar tstellar merged commit 2836d8e into llvm:main Feb 21, 2024
4 checks passed
@tstellar tstellar added this to the LLVM 18.X Release milestone Feb 21, 2024
@tstellar
Copy link
Collaborator Author

/cherry-pick 2836d8e

llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Feb 21, 2024
The default GitHub token does not have read permissions on the org, so
we need to use a custom token in order to read the members of the
llvm-release-managers team.

(cherry picked from commit 2836d8e)
@llvmbot
Copy link

llvmbot commented Feb 21, 2024

/pull-request #82453

llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Feb 21, 2024
The default GitHub token does not have read permissions on the org, so
we need to use a custom token in order to read the members of the
llvm-release-managers team.

(cherry picked from commit 2836d8e)
@pointhex pointhex mentioned this pull request May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

3 participants