Skip to content

Commit b272bca

Browse files
authored
Revert "Better handling of git actor" (#425)
This reverts commit 8a8cc1a.
1 parent 8a8cc1a commit b272bca

File tree

7 files changed

+24
-30
lines changed

7 files changed

+24
-30
lines changed

.github/workflows/prep-release.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ on:
2424
type: boolean
2525
jobs:
2626
prep_release:
27-
permissions:
28-
contents: write
2927
runs-on: ubuntu-latest
3028
strategy:
3129
fail-fast: true
@@ -42,7 +40,7 @@ jobs:
4240
id: prep-release
4341
uses: jupyter-server/jupyter_releaser/.github/actions/prep-release@v2
4442
with:
45-
token: ${{ secrets.GITHUB_TOKEN }}
43+
token: ${{ secrets.ADMIN_GITHUB_TOKEN }}
4644
version_spec: ${{ github.event.inputs.version_spec }}
4745
post_version_spec: ${{ github.event.inputs.post_version_spec }}
4846
target: ${{ github.event.inputs.target }}

.github/workflows/publish-release.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ on:
1717

1818
jobs:
1919
publish_release:
20-
permissions:
21-
contents: write
2220
runs-on: ubuntu-latest
2321
strategy:
2422
fail-fast: true
@@ -35,7 +33,7 @@ jobs:
3533
id: populate-release
3634
uses: jupyter-server/jupyter_releaser/.github/actions/populate-release@v2
3735
with:
38-
token: ${{ secrets.GITHUB_TOKEN }}
36+
token: ${{ secrets.ADMIN_GITHUB_TOKEN }}
3937
target: ${{ github.event.inputs.target }}
4038
branch: ${{ github.event.inputs.branch }}
4139
release_url: ${{ github.event.inputs.release_url }}
@@ -50,7 +48,7 @@ jobs:
5048
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
5149
uses: jupyter-server/jupyter-releaser/.github/actions/finalize-release@v2
5250
with:
53-
token: ${{ secrets.GITHUB_TOKEN }}
51+
token: ${{ secrets.ADMIN_GITHUB_TOKEN }}
5452
target: ${{ github.event.inputs.target }}
5553
release_url: ${{ steps.populate-release.outputs.release_url }}
5654

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ To install the latest release locally, make sure you have
2121

2222
## Checklist for Adoption
2323

24-
See the [adoption guides](https://jupyter-releaser.readthedocs.io/en/latest/how_to_guides/index.html).
24+
See the [adoption docs](https://jupyter-releaser.readthedocs.io/en/latest/how_to_guides/convert_repo.html).
2525

2626
## Actions
2727

2828
GitHub actions scripts are available to draft a changelog, draft a release, publish a release, and check a release.
2929

3030
See the [action details documentation](https://jupyter-releaser.readthedocs.io/en/latest/background/theory.html#action-details) for more information.
3131

32-
The actions can be run on a [fork](https://jupyter-releaser.readthedocs.io/en/latest/how_to_guides/convert_repo_from_releaser.html) of `jupyter_releaser` and target multiple
33-
repositories, or run as workflows on the [source repositories](https://jupyter-releaser.readthedocs.io/en/latest/how_to_guides/convert_repo_from_repo.html), using
32+
The actions can be run on a [fork](https://jupyter-releaser.readthedocs.io/en/latest/how_to_guides/convert_repo_from_releaser.html#) of `jupyter_releaser` and target multiple
33+
repositories, or run as workflows on the [source repositories](https://jupyter-releaser.readthedocs.io/en/latest/how_to_guides/convert_repo_from_repo), using
3434
shared credentials.

docs/source/how_to_guides/convert_repo_from_repo.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ See [checklist](#Checklist-for-Adoption) below for details:
1414

1515
## Checklist for Adoption
1616

17+
- [ ] Add a [GitHub Access token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) with access to target GitHub repo to run GitHub Actions, saved as
18+
`ADMIN_GITHUB_TOKEN` in the [repository secrets](https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository).
19+
The token needs to have `public_repo` and `repo:status` permissions.
1720
- [ ] Add access token for the [PyPI registry](https://packaging.python.org/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/#saving-credentials-on-github) stored as `PYPI_TOKEN`.
1821
_Note_ For security reasons, it is recommended that you scope the access
1922
to a single repository.
2023
- [ ] If needed, add access token for [npm](https://docs.npmjs.com/creating-and-viewing-access-tokens), saved as `NPM_TOKEN`.
21-
- [ ] Ensure that only trusted users with 2FA have admin access to the
22-
repository, since they will be able to trigger releases.
24+
- [ ] Enable tag protection for all tags (`*`), to ensure that only users
25+
with admin write permissions can publish witht he shared credentials.
2326
- [ ] Switch to Markdown Changelog
2427
- We recommend [MyST](https://myst-parser.readthedocs.io/en/latest/?badge=latest), especially if some of your docs are in reStructuredText.
2528
- Can use `pandoc -s changelog.rst -o changelog.md` and some hand edits as needed.

jupyter_releaser/lib.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -410,18 +410,19 @@ def prep_git(ref, branch, repo, auth, username, url):
410410
"""Set up git"""
411411
repo = repo or util.get_repo()
412412

413+
user_name = ""
413414
try:
414-
util.run("git config --global user.email")
415-
has_git_config = True
415+
user_name = util.run("git config --global user.email")
416416
except Exception:
417-
has_git_config = False
417+
pass
418418

419-
if not has_git_config:
420-
# Default to the GitHub Actions bot
419+
if not user_name:
420+
# Use email address for the GitHub Actions bot
421421
# https://github.community/t/github-actions-bot-email-address/17204/6
422-
git_user_name = username or "41898282+github-actions[bot]"
423-
util.run(f'git config --global user.email "{git_user_name}@users.noreply.github.com"')
424-
util.run(f'git config --global user.name "{git_user_name}"')
422+
util.run(
423+
'git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"'
424+
)
425+
util.run('git config --global user.name "GitHub Action"')
425426

426427
# Set up the repository
427428
checkout_dir = os.environ.get("RH_CHECKOUT_DIR", util.CHECKOUT_NAME)

jupyter_releaser/tests/test_cli.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,19 @@ def test_prep_git_full(py_package, tmp_path, mocker, runner):
9494
os.mkdir(util.CHECKOUT_NAME)
9595

9696
runner(["prep-git"], env=env)
97-
9897
mock_run.assert_has_calls(
9998
[
100-
call("echo before-prep-git >> 'log.txt'"),
10199
call("git config --global user.email"),
100+
call(
101+
'git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"'
102+
),
103+
call('git config --global user.name "GitHub Action"'),
102104
call("git init .jupyter_releaser_checkout"),
103105
call("git remote add origin https://snuffy:[email protected]/baz/bar.git"),
104106
call(f"{GIT_FETCH_CMD} --tags --force"),
105107
call(f"{GIT_FETCH_CMD} +refs/pull/42:refs/pull/42"),
106108
call(f"{GIT_FETCH_CMD} refs/pull/42"),
107109
call("git checkout -B foo refs/pull/42"),
108-
call("git symbolic-ref -q HEAD"),
109110
]
110111
)
111112

jupyter_releaser/util.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -558,13 +558,6 @@ def prepare_environment(fetch_draft_release=True):
558558
auth = os.environ.get("GITHUB_ACCESS_TOKEN", "")
559559
gh = get_gh_object(dry_run=dry_run, owner=owner, repo=repo_name, token=auth)
560560

561-
# Ensure the user is an admin.
562-
if not dry_run:
563-
user = gh.users.get_authenticated()["login"]
564-
collab_level = gh.repos.get_collaborator_permission_level(user)
565-
if not collab_level["permission"] == "admin":
566-
raise RuntimeError(f"User {user} does not have admin permission")
567-
568561
# Get the latest draft release if none is given.
569562
release_url = os.environ.get("RH_RELEASE_URL")
570563
log(f"Environment release url was {release_url}")

0 commit comments

Comments
 (0)