- Notifications
You must be signed in to change notification settings - Fork262
Implement $CI_JOB_TOKEN support in releases#1098
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
KundaPanda wants to merge6 commits intopython-semantic-release:masterChoose a base branch fromKundaPanda:master
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes fromall commits
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
1f0f4e4 test(rvcs-gitlab): add a unit test to validate `$CI_JOB_TOKEN` detection
KundaPandab301d2f test(rvcs-gitlab): add an E2E test to validate `$CI_JOB_TOKEN` detect…
KundaPandab3a4d48 feat(gitlab): add `$CI_JOB_TOKEN` support for GitLab v17.2 and greater
KundaPanda3717b1f feat(rvcs-gitlab): default to `$CI_JOB_TOKEN` if missing
KundaPanda0cd83ee docs(rvcs-gitlab): add description for `$CI_JOB_TOKEN` usage
KundaPanda08ef8ee adjustment
codejedi365File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletionsdocs/configuration/configuration.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
56 changes: 53 additions & 3 deletionssrc/semantic_release/hvcs/gitlab.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletionstests/e2e/cmd_version/test_version_gitlab_auth.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| from __future__ import annotations | ||
| import os | ||
| from typing import TYPE_CHECKING | ||
| from unittest import mock | ||
| import pytest | ||
| from semantic_release.cli.commands.main import main | ||
| from tests.const import MAIN_PROG_NAME, VERSION_SUBCMD | ||
| from tests.util import assert_successful_exit_code | ||
| if TYPE_CHECKING: | ||
| from unittest.mock import MagicMock | ||
| from click.testing import CliRunner | ||
| from git.repo import Repo | ||
| from requests_mock import Mocker | ||
| from tests.e2e.conftest import RetrieveRuntimeContextFn | ||
| from tests.fixtures.example_project import UseHvcsFn, UseReleaseNotesTemplateFn | ||
| @pytest.mark.parametrize( | ||
| "tokens", | ||
| [ | ||
| ("gitlab-token", "gitlab-private-token"), | ||
| ("gitlab-token", "gitlab-token"), | ||
| ("", "gitlab-token"), | ||
| ("gitlab-token", None), | ||
| ("gitlab-token", ""), | ||
| (None, "gitlab-private-token"), | ||
| (None, None), | ||
| ], | ||
| ) | ||
| def test_gitlab_release_tokens( | ||
| cli_runner: CliRunner, | ||
| use_release_notes_template: UseReleaseNotesTemplateFn, | ||
| retrieve_runtime_context: RetrieveRuntimeContextFn, | ||
| mocked_git_push: MagicMock, | ||
| requests_mock: Mocker, | ||
| use_gitlab_hvcs: UseHvcsFn, | ||
| tokens: tuple[str, str], | ||
| repo_w_no_tags_angular_commits: Repo, | ||
| ) -> None: | ||
| """Verify that gitlab tokens are used correctly.""" | ||
| # Setup | ||
| private_token, job_token = tokens | ||
| use_gitlab_hvcs() | ||
| requests_mock.register_uri( | ||
| "POST", | ||
| "https://example.com/api/v4/projects/999/releases", | ||
| json={"id": 999}, | ||
| headers={"Content-Type": "application/json"}, | ||
| ) | ||
| requests_mock.register_uri( | ||
| "GET", | ||
| "https://example.com/api/v4/projects/example_owner%2Fexample_repo", | ||
| json={"id": 999}, | ||
| headers={"Content-Type": "application/json"}, | ||
| ) | ||
| env_dict = {} | ||
| if private_token is not None: | ||
| env_dict["GITLAB_TOKEN"] = private_token | ||
| if job_token is not None: | ||
| env_dict["CI_JOB_TOKEN"] = job_token | ||
| with mock.patch.dict(os.environ, env_dict): | ||
| # Act | ||
| cli_cmd = [MAIN_PROG_NAME, VERSION_SUBCMD, "--vcs-release"] | ||
| result = cli_runner.invoke(main, cli_cmd[1:]) | ||
| # Assert | ||
| assert_successful_exit_code(result, cli_cmd) | ||
| assert mocked_git_push.call_count == 2 # 1 for commit, 1 for tag | ||
| assert requests_mock.call_count == 2 | ||
| assert requests_mock.last_request is not None | ||
| assert requests_mock.request_history[0].method == "GET" | ||
| assert requests_mock.request_history[1].method == "POST" | ||
| job_token_header = "JOB-TOKEN" | ||
| private_token_header = "PRIVATE-TOKEN" | ||
| for request in requests_mock.request_history: | ||
| if private_token and private_token != job_token: | ||
| assert request._request.headers[private_token_header] == private_token | ||
| assert job_token_header not in request._request.headers | ||
| elif job_token: | ||
| assert request._request.headers[job_token_header] == job_token | ||
| assert private_token_header not in request._request.headers | ||
| else: | ||
| assert private_token_header not in request._request.headers | ||
| assert job_token_header not in request._request.headers |
25 changes: 24 additions & 1 deletiontests/unit/semantic_release/hvcs/test_gitlab.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.