From 683d7c256218b559d36dc3e74e0f87f07a8e27f9 Mon Sep 17 00:00:00 2001 From: Julien Carsique Date: Tue, 1 Jul 2025 16:46:41 +0200 Subject: [PATCH] BUILD-8099 promote action --- .github/workflows/test-shell-scripts.yml | 2 - .gitignore | 1 + .shellspec | 2 +- CONTRIBUTE.md | 18 +- README.md | 35 +++ build-poetry/action.yml | 3 +- build-poetry/build.sh | 34 +-- promote/action.yml | 31 +++ promote/mise.local.toml | 2 + promote/promote.sh | 193 +++++++++++++++ sonar-project.properties | 2 +- spec/build-poetry_spec.sh | 98 ++++---- spec/promote-poetry_spec.sh | 303 +++++++++++++++++++++++ 13 files changed, 654 insertions(+), 70 deletions(-) create mode 100644 promote/action.yml create mode 100644 promote/mise.local.toml create mode 100755 promote/promote.sh create mode 100644 spec/promote-poetry_spec.sh diff --git a/.github/workflows/test-shell-scripts.yml b/.github/workflows/test-shell-scripts.yml index 7cd46591..7d3c473c 100644 --- a/.github/workflows/test-shell-scripts.yml +++ b/.github/workflows/test-shell-scripts.yml @@ -25,8 +25,6 @@ jobs: sudo dpkg -i kcov_38+dfsg-1_amd64.deb rm kcov_38+dfsg-1_amd64.deb - pwd - ls -la ./run_shell_tests.sh - name: Vault id: secrets diff --git a/.gitignore b/.gitignore index 5bf2c9f1..6758cec4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /coverage/ /.scannerwork/ /build_number.txt +/.shellspec-quick.log diff --git a/.shellspec b/.shellspec index 13493338..51c30c9e 100644 --- a/.shellspec +++ b/.shellspec @@ -1,5 +1,5 @@ # kcov (coverage) options ---kcov-options "--include-pattern=build-poetry,get-build-number,pr_cleanup" +--kcov-options "--include-pattern=build-poetry,get-build-number,pr_cleanup,promote" # --kcov-options "--exclude-pattern=.github,.idea,.git" # define minimum coverage (fail otherwise) diff --git a/CONTRIBUTE.md b/CONTRIBUTE.md index 83df393d..46a7124f 100644 --- a/CONTRIBUTE.md +++ b/CONTRIBUTE.md @@ -50,6 +50,18 @@ The coverage report is available here: `coverage/index.html` Use `Dump` in the spec file to print the variables and their values during the test execution. +Use ShellSpec options like `-x`, `-X` to run the tests in debug mode. + +Use ShellSpec options like `-q` (`--quick`), `-n` (`--next-failure`)... to iterate on the tests and debug them. + +```shell +# List all examples in the spec files, with IDs +shellspec --kcov --list examples + +# List all examples in the spec files, with line numbers +shellspec --kcov --list examples:lineno +``` + ## Project structure ```text @@ -73,10 +85,12 @@ Add a section in the README.md file to document the new action, including its us Add the action folder to the `.shellspec` configuration file to include it in the tests. +Also add the action to the `sonar-project.properties` file to include its coverage in the SonarQube analysis. + Add a new spec file in the `spec` directory for the action. Use the existing tests as examples for writing your own tests. -Only create Action test workflow when it completes the ShellSpec tests, and does not require complex setup or external dependencies. -The actions are used in the dummy repositories, so they are tested in the CI/CD environment. +Only create an Action test workflow when it completes the ShellSpec tests, and does not require complex setup or external dependencies. +The actions are used in the dummy repositories, so they are tested for real in the CI/CD environment. ### Test Guidelines diff --git a/README.md b/README.md index b706df0a..97b3860f 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,41 @@ jobs: - `public-deployer` or `qa-deployer` Artifactory roles for the deployment. - `qa-deployer` Artifactory role for the QA deploy. +## `promote` + +This action promotes a build in JFrog Artifactory and updates the GitHub status check accordingly. + +The GitHub status check is named `repox-${GITHUB_REF_NAME}`. + +### Usage + +```yaml + promote: + needs: + - build + concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.ref_name != github.event.repository.default_branch }} + runs-on: ubuntu-24.04-large + name: Promote + permissions: + id-token: write + contents: write + steps: + - uses: SonarSource/ci-github-actions/get-build-number@v1 + - uses: SonarSource/ci-github-actions/promote@v1 +``` + +⚠️ Required GitHub permissions: + +- `id-token: write` +- `contents: write` + +⚠️ Required Vault permissions: + +- `promoter` Artifactory role for the promotion. +- `promotion` GitHub token. + ## `pr-cleanup` Automatically clean up caches and artifacts associated with a pull request when it is closed. diff --git a/build-poetry/action.yml b/build-poetry/action.yml index da75c2e3..0d2bf350 100644 --- a/build-poetry/action.yml +++ b/build-poetry/action.yml @@ -3,8 +3,7 @@ name: Build Poetry description: GitHub Action to build, analyze, and deploy a Python project using Poetry inputs: public: - description: Whether to build and deploy with/to public repositories. Defaults to `true` for public repositories (OSS), and `false` for - private repositories. + description: Whether to build and deploy with/to public repositories. Set to `true` for public repositories (OSS), `false` for private. default: ${{ github.event.repository.visibility == 'public' && 'true' || 'false' }} artifactory-reader-role: description: Suffix for the Artifactory reader role in Vault. Defaults to `private-reader` for private repositories, and `public-reader` diff --git a/build-poetry/build.sh b/build-poetry/build.sh index b92b1b7c..666c9cbd 100755 --- a/build-poetry/build.sh +++ b/build-poetry/build.sh @@ -1,27 +1,28 @@ #!/bin/bash # Regular way to build and deploy a SonarSource Poetry project. # Environment variables: -# - ARTIFACTORY_URL: Repox URL -# - ARTIFACTORY_PYPI_REPO: repository to install dependencies from (sonarsource-pypi) -# - ARTIFACTORY_ACCESS_TOKEN: access token to access the repository -# - ARTIFACTORY_DEPLOY_REPO: deployment repository (sonarsource-pypi-public-qa or sonarsource-pypi-private-qa) -# - ARTIFACTORY_DEPLOY_ACCESS_TOKEN: access token to deploy to the repository -# - GITHUB_REF_NAME: the short ref name of the branch or tag (e.g. main, branch-123, dogfood-on-123) -# - DEFAULT_BRANCH: default branch (e.g. main), defaults to the repository configuration -# - BUILD_NUMBER: build number (e.g. 42) -# - GITHUB_REPOSITORY: repository name (e.g. sonarsource/sonar-dummy-poetry) -# - GITHUB_EVENT_NAME: event name (e.g. push, pull_request) -# - GITHUB_EVENT_PATH: The path to the event webhook payload file. For example, /github/workflow/event.json. +# - ARTIFACTORY_URL: Repox URL. +# - ARTIFACTORY_PYPI_REPO: Repository to install dependencies from (sonarsource-pypi) +# - ARTIFACTORY_ACCESS_TOKEN: Access token to access the repository +# - ARTIFACTORY_DEPLOY_REPO: Deployment repository (sonarsource-pypi-public-qa or sonarsource-pypi-private-qa) +# - ARTIFACTORY_DEPLOY_ACCESS_TOKEN: Access token to deploy to the repository +# - GITHUB_REF_NAME: Short ref name of the branch or tag (e.g. main, branch-123, dogfood-on-123) +# - DEFAULT_BRANCH: Default branch (e.g. main), defaults to the repository configuration +# - BUILD_NUMBER: Build number (e.g. 42) +# - GITHUB_REPOSITORY: Repository name (e.g. sonarsource/sonar-dummy-poetry) +# - GITHUB_EVENT_NAME: Event name (e.g. push, pull_request) +# - GITHUB_EVENT_PATH: Path to the event webhook payload file. For example, /github/workflow/event.json. # shellcheck source-path=SCRIPTDIR set -euo pipefail : "${ARTIFACTORY_URL:="https://repox.jfrog.io/artifactory"}" : "${ARTIFACTORY_PYPI_REPO:?}" "${ARTIFACTORY_ACCESS_TOKEN:?}" "${ARTIFACTORY_DEPLOY_REPO:?}" "${ARTIFACTORY_DEPLOY_ACCESS_TOKEN:?}" -: "${GITHUB_REF_NAME:?}" "${BUILD_NUMBER:?}" "${GITHUB_REPOSITORY:?}" -: "${GITHUB_EVENT_NAME:?}" "${GITHUB_EVENT_PATH:?}" +: "${GITHUB_REF_NAME:?}" "${BUILD_NUMBER:?}" "${GITHUB_REPOSITORY:?}" "${GITHUB_EVENT_NAME:?}" "${GITHUB_EVENT_PATH:?}" +: "${GITHUB_ENV:?}" # "${GITHUB_OUTPUT:?}" check_tool() { + # Check if a command is available and runs it, typically: 'some_tool --version' if ! command -v "$1"; then echo "$1 is not installed." >&2 return 1 @@ -85,12 +86,13 @@ jfrog_poetry_publish() { popd jf rt build-collect-env "$PROJECT" "$BUILD_NUMBER" jf rt build-publish "$PROJECT" "$BUILD_NUMBER" \ - --env-include 'PROJECT;GIT_*;*VERSION*;BUILD_*;GITHUB_*;*BRANCH*;*ID;PULL_REQUEST*' \ + --env-include 'PROJECT;GIT_*;*VERSION*;BUILD_*;GITHUB_*;*BRANCH*;*ID;PULL_REQUEST*;ARTIFACTORY*' \ --env-exclude "*login*;*pass*;*psw*;*pwd*;*secret*;*key*;*token*;*auth*" \ --overwrite # avoid duplicate builds on re-runs } -main() { +build-poetry() { + check_tool jq --version check_tool python --version check_tool poetry --version check_tool jf --version @@ -122,5 +124,5 @@ main() { } if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then - main + build-poetry fi diff --git a/promote/action.yml b/promote/action.yml new file mode 100644 index 00000000..8872029c --- /dev/null +++ b/promote/action.yml @@ -0,0 +1,31 @@ +--- +name: Promote +description: GitHub Action to promote a project +inputs: + public: + description: Whether to build and deploy with/to public repositories. Set to `true` for public repositories (OSS), `false` for private. + default: ${{ github.event.repository.visibility == 'public' && 'true' || 'false' }} + +runs: + using: composite + steps: + - name: Set build parameters + shell: bash + run: | + cp ${GITHUB_ACTION_PATH}/mise.local.toml mise.local.toml + - name: Vault + id: secrets + uses: SonarSource/vault-action-wrapper@d6d745ffdbc82b040df839b903bc33b5592cd6b0 # 3.0.2 + with: + secrets: | + development/artifactory/token/{REPO_OWNER_NAME_DASH}-promoter access_token | ARTIFACTORY_PROMOTE_ACCESS_TOKEN; + development/github/token/{REPO_OWNER_NAME_DASH}-promotion token | GITHUB_TOKEN; + - uses: jdx/mise-action@5cb1df66ed5e1fb3c670ea0b62fd17a76979826a # v2.3.1 + - name: Promote artifacts + shell: bash + env: + ARTIFACTORY_PROMOTE_ACCESS_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_PROMOTE_ACCESS_TOKEN }} + GITHUB_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).GITHUB_TOKEN }} + DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} + run: | + ${GITHUB_ACTION_PATH}/promote.sh diff --git a/promote/mise.local.toml b/promote/mise.local.toml new file mode 100644 index 00000000..2b1cde01 --- /dev/null +++ b/promote/mise.local.toml @@ -0,0 +1,2 @@ +[tools] +jfrog-cli = "2.77.0" diff --git a/promote/promote.sh b/promote/promote.sh new file mode 100755 index 00000000..841c4f23 --- /dev/null +++ b/promote/promote.sh @@ -0,0 +1,193 @@ +#!/bin/bash +# Regular way to promote a project build: JFrog Artifactory build promotion, and GitHub status check update +# Environment variables: +# - ARTIFACTORY_URL: Repox URL. +# - ARTIFACTORY_PROMOTE_ACCESS_TOKEN: Access token to promote builds +# - GITHUB_REF_NAME: Short ref name of the branch or tag (e.g. main, branch-123, dogfood-on-123) +# - DEFAULT_BRANCH: Default branch (e.g. main), defaults to the repository configuration +# - BUILD_NUMBER: Build number (e.g. 42) +# - GITHUB_REPOSITORY: Repository name (e.g. sonarsource/sonar-dummy-poetry) +# - GITHUB_EVENT_NAME: Event name (e.g. push, pull_request) +# - GITHUB_EVENT_PATH: Path to the event webhook payload file. For example, /github/workflow/event.json. +# - MULTI_REPO_PROMOTE: If true, promotes to multiple repositories (default: false) +# - ARTIFACTORY_DEPLOY_REPO: Repository to deploy to. If not set, it will be retrieved from the build info. +# - ARTIFACTORY_TARGET: Target repository for the promotion. If not set, it will be determined based on the branch type. +# Required properties in the build info: +# - buildInfo.env.ARTIFACTORY_DEPLOY_REPO: Repository to deploy to (e.g. sonarsource-deploy-qa) +# - buildInfo.env.PROJECT_VERSION: Version of the project (e.g. 1.2.3) +# shellcheck source-path=SCRIPTDIR + +set -euo pipefail + +: "${ARTIFACTORY_URL:="https://repox.jfrog.io/artifactory"}" +: "${ARTIFACTORY_PROMOTE_ACCESS_TOKEN:?}" +: "${GITHUB_REF_NAME:?}" "${BUILD_NUMBER:?}" "${GITHUB_REPOSITORY:?}" "${GITHUB_EVENT_NAME:?}" "${GITHUB_EVENT_PATH:?}" "${GITHUB_TOKEN:?}" +: "${GITHUB_SHA:?}" +GH_API_VERSION_HEADER="X-GitHub-Api-Version: 2022-11-28" +BUILD_INFO_FILE=".build-info" +rm -f "$BUILD_INFO_FILE" + +: "${MULTI_REPO_PROMOTE:=false}" +MULTI_REPO_SRC_PRIVATE=sonarsource-private-qa +MULTI_REPO_SRC_PUBLIC=sonarsource-public-qa + +check_tool() { + # Check if a command is available and runs it, typically: 'some_tool --version' + if ! command -v "$1"; then + echo "$1 is not installed." >&2 + return 1 + fi + "$@" +} + +is_main_branch() { + [[ "$GITHUB_REF_NAME" = "$DEFAULT_BRANCH" ]] +} + +is_maintenance_branch() { + [[ "${GITHUB_REF_NAME}" == "branch-"* ]] +} + +is_pull_request() { + [[ "$GITHUB_EVENT_NAME" == "pull_request" ]] +} + +is_dogfood_branch() { + [[ "${GITHUB_REF_NAME}" == "dogfood-on-"* ]] +} + +is_merge_queue_branch() { + [[ "${GITHUB_REF_NAME}" == "gh-readonly-queue/"* ]] +} + +set_build_env() { + DEFAULT_BRANCH=${DEFAULT_BRANCH:=$(gh repo view --json defaultBranchRef --jq ".defaultBranchRef.name")} + export PROJECT=${GITHUB_REPOSITORY#*/} + echo "PROJECT: $PROJECT" + export DEFAULT_BRANCH +} + +check_branch() { + if is_merge_queue_branch; then + echo "Github merge queue detected: promotion skipped." + exit 0 + fi + if ! (is_pull_request || is_main_branch || is_maintenance_branch || is_dogfood_branch); then + echo "Promotion is only available for pull requests, main branch, maintenance branches, or dogfood branches." >&2 + echo "Current branch: ${GITHUB_REF_NAME} (GITHUB_EVENT_NAME: ${GITHUB_EVENT_NAME})" >&2 + return 1 + fi +} + +jfrog_config_repox() { + jf config remove repox + jf config add repox --artifactory-url "$ARTIFACTORY_URL" --access-token "$ARTIFACTORY_PROMOTE_ACCESS_TOKEN" +} + +get_target_repos() { + # Set targetRepo1 and targetRepo2 based on the branch type for multi-promotion + if is_pull_request; then + targetRepo1="sonarsource-private-dev" + targetRepo2="sonarsource-public-dev" + elif is_main_branch || is_maintenance_branch; then + targetRepo1="sonarsource-private-builds" + targetRepo2="sonarsource-public-builds" + elif is_dogfood_branch; then + targetRepo1="sonarsource-dogfood-builds" + targetRepo2="sonarsource-dogfood-builds" + fi +} + +get_build_info_property() { + property="$1" + if ! [[ -s "$BUILD_INFO_FILE" ]]; then + jf rt curl "api/build/$PROJECT/$BUILD_NUMBER" > "$BUILD_INFO_FILE" + fi + property_value=$(jq -r ".buildInfo.properties.\"buildInfo.env.$property\"" "$BUILD_INFO_FILE") + if [[ "$property_value" == "null" || -z "$property_value" ]]; then + echo "Failed to retrieve $property from buildInfo for build ${PROJECT}/${BUILD_NUMBER}" >&2 + jq -r '.errors' "$BUILD_INFO_FILE" >&2 + return 1 + fi + echo "$property_value" +} + +get_target_repo() { + # Set targetRepo based on the branch type and ARTIFACTORY_DEPLOY_REPO, if not already set + if [[ -n ${ARTIFACTORY_TARGET:-} ]]; then + targetRepo="$ARTIFACTORY_TARGET" + return + fi + : "${ARTIFACTORY_DEPLOY_REPO:=$(get_build_info_property ARTIFACTORY_DEPLOY_REPO)}" + echo "ARTIFACTORY_DEPLOY_REPO=$ARTIFACTORY_DEPLOY_REPO" + if is_pull_request; then + targetRepo=${ARTIFACTORY_DEPLOY_REPO/%qa/dev} + elif is_main_branch || is_maintenance_branch; then + targetRepo=${ARTIFACTORY_DEPLOY_REPO/%qa/builds} + elif is_dogfood_branch; then + targetRepo=sonarsource-dogfood-builds + fi +} + +promote_multi() { + # Call to https://github.com/SonarSource/re-tooling/tree/main/artifactory-user-plugins/multiRepoPromote + echo "Promote $PROJECT/$BUILD_NUMBER build artifacts to $targetRepo1 and $targetRepo2" + local promoteUrl="api/plugins/execute/multiRepoPromote?" + promoteUrl+="params=buildName=$PROJECT;buildNumber=$BUILD_NUMBER;status=$status" + promoteUrl+=";src1=$MULTI_REPO_SRC_PRIVATE;target1=$targetRepo1" + promoteUrl+=";src2=$MULTI_REPO_SRC_PUBLIC;target2=$targetRepo2" + jf rt curl "$promoteUrl" +} + +promote_mono() { + # Promote JFrog Artifactory build + echo "Promote $PROJECT/$BUILD_NUMBER build artifacts to $targetRepo" + jf rt bpr --status "$status" "$PROJECT" "$BUILD_NUMBER" "$targetRepo" +} + +github_notify_promotion() { + local project_version longDescription shortDescription buildUrl githubApiUrl + project_version=$(get_build_info_property PROJECT_VERSION) + longDescription="Latest promoted build of '${project_version}' from branch '${GITHUB_REF_NAME}'" + shortDescription=${longDescription:0:140} # required for GH API endpoint (max 140 chars) + buildUrl="${ARTIFACTORY_URL}/ui/builds/${PROJECT}/${BUILD_NUMBER}/" + githubApiUrl="https://api.github.com/repos/${GITHUB_REPOSITORY}/statuses/${GITHUB_SHA}" + gh api -X POST -H "$GH_API_VERSION_HEADER" "$githubApiUrl" -H "Content-Type: application/json" --input - < --access-token " - The line 12 should equal "jf poetry-config --server-id-resolve repox --repo-resolve " - The line 13 should equal "jf poetry install --build-name=my-repo --build-number=42" - The line 14 should equal "poetry build" - End + The status should be success + The lines of stdout should equal 16 + The line 1 should include "jq" + The line 2 should include "jq" + The line 3 should include "python" + The line 4 should include "python" + The line 5 should include "poetry" + The line 6 should include "poetry" + The line 7 should include "jf" + The line 8 should include "jf" + The line 9 should equal "PROJECT: my-repo" + The line 10 should equal "PULL_REQUEST: false" + The line 11 should equal "Replacing version 1.2 with 1.2.0.42" + The line 12 should equal "poetry version 1.2.0.42" + The line 13 should equal "jf config add repox --artifactory-url https://dummy.repox --access-token dummy access token" + The line 14 should equal "jf poetry-config --server-id-resolve repox --repo-resolve " + The line 15 should equal "jf poetry install --build-name=my-repo --build-number=42" + The line 16 should equal "poetry build" + End End Include build-poetry/build.sh -Describe 'check_tool' - It 'should report not installed tool' +Describe 'check_tool()' + It 'reports not installed tool' When call check_tool some_tool The status should be failure The line 1 of error should equal "some_tool is not installed." End End -Describe 'set_build_env' - It 'should set the default branch and project name' +Describe 'set_build_env()' + It 'sets the default branch and project name' When call set_build_env The line 1 should equal "PROJECT: my-repo" The line 2 should equal "PULL_REQUEST: false" - The variable DEFAULT_BRANCH should equal "master" + The variable DEFAULT_BRANCH should equal "main" The variable PROJECT should equal "my-repo" The variable PULL_REQUEST should equal "false" The variable PULL_REQUEST_SHA should be undefined End - It 'should set PULL_REQUEST and PULL_REQUEST_SHA for pull requests' + It 'sets PULL_REQUEST and PULL_REQUEST_SHA for pull requests' export GITHUB_EVENT_NAME="pull_request" echo '{"number": 123, "pull_request": {"base": {"sha": "abc123"}}}' > "$GITHUB_EVENT_PATH" @@ -95,8 +101,8 @@ Describe 'set_build_env' End End -Describe 'set_project_version' - It 'should append .0 given version is 1.2 and append BUILD_NUMBER' +Describe 'set_project_version()' + It 'appends .0 given version is 1.2 and append BUILD_NUMBER' Mock poetry if [[ "$*" == "version -s" ]]; then echo "1.2" @@ -109,7 +115,7 @@ Describe 'set_project_version' The variable PROJECT_VERSION should equal "1.2.0.42" End - It 'should append BUILD_NUMBER given version is 1.2.3' + It 'appends BUILD_NUMBER given version is 1.2.3' Mock poetry if [[ "$*" == "version -s" ]]; then echo "1.2.3" @@ -122,7 +128,7 @@ Describe 'set_project_version' The variable PROJECT_VERSION should equal "1.2.3.42" End - It 'should replace dev with BUILD_NUMBER given version is 1.2.3.dev' + It 'replaces dev with BUILD_NUMBER given version is 1.2.3.dev' Mock poetry if [[ "$*" == "version -s" ]]; then echo "1.2.3.dev" @@ -135,7 +141,7 @@ Describe 'set_project_version' The variable PROJECT_VERSION should equal "1.2.3.42" End - It 'should replace 41 with BUILD_NUMBER given version is 1.2.3.dev' + It 'replaces 41 with BUILD_NUMBER given version is 1.2.3.dev' Mock poetry if [[ "$*" == "version -s" ]]; then echo "1.2.3.41" @@ -149,7 +155,7 @@ Describe 'set_project_version' The variable PROJECT_VERSION should equal "1.2.3.42" End - It 'should return error message if version cannot be retrieved' + It 'returns error message if version cannot be retrieved' Mock poetry if [[ "$*" == "version -s" ]]; then echo "Failed to get version" @@ -166,9 +172,9 @@ Describe 'set_project_version' End End -Describe 'jfrog_poetry_install' +Describe 'jfrog_poetry_install()' export PROJECT="my-repo" - It 'should install Poetry dependencies using JFrog CLI' + It 'installs Poetry dependencies using JFrog CLI' When call jfrog_poetry_install The line 1 should include "jf config add repox" The line 2 should include "jf poetry-config" @@ -176,7 +182,7 @@ Describe 'jfrog_poetry_install' End End -Describe 'main' +Describe 'build-poetry()' setup() { mkdir -p dist } @@ -198,14 +204,14 @@ Describe 'main' Mock jfrog_poetry_install End - It 'should build and publish when it is master branch and not a PR' + It 'builds and publishes when on the default branch (main) and not a PR' unset PULL_REQUEST - export GITHUB_REF_NAME="master" + export GITHUB_REF_NAME="main" - When call main + When call build-poetry The line 1 should equal 'poetry build' The line 2 should equal "jf config remove repox" - The line 3 should equal "jf config add repox --artifactory-url --access-token " + The line 3 should equal "jf config add repox --artifactory-url https://dummy.repox --access-token " The line 4 should include "/dist" The line 5 should equal "jf rt upload ./ /poetry/1.0.0.42/ --module=poetry:1.0.0.42 --build-name=my-repo --build-number=42" # ignore line 6 with popd output @@ -215,24 +221,24 @@ Describe 'main' The status should be success End - It 'should skip when it is a PR and DEPLOY_PULL_REQUEST is not true' + It 'skips when on a PR and DEPLOY_PULL_REQUEST is not true' export PULL_REQUEST="123" export GITHUB_REF_NAME="test/pull-request/123" - When call main + When call build-poetry The output should equal 'poetry build' The status should be success End - It 'should build and publish when it is a PR and DEPLOY_PULL_REQUEST is true' + It 'builds and publishes when on a PR and DEPLOY_PULL_REQUEST is true' export PULL_REQUEST="123" export GITHUB_REF_NAME="test/pull-request/123" export DEPLOY_PULL_REQUEST="true" - When call main + When call build-poetry The line 1 should equal 'poetry build' The line 2 should equal "jf config remove repox" - The line 3 should equal "jf config add repox --artifactory-url --access-token " + The line 3 should equal "jf config add repox --artifactory-url https://dummy.repox --access-token " The line 4 should include "/dist" The line 5 should equal "jf rt upload ./ /poetry/1.0.0.42/ --module=poetry:1.0.0.42 --build-name=my-repo --build-number=42" # ignore line 6 with popd output diff --git a/spec/promote-poetry_spec.sh b/spec/promote-poetry_spec.sh new file mode 100644 index 00000000..f2159002 --- /dev/null +++ b/spec/promote-poetry_spec.sh @@ -0,0 +1,303 @@ +#!/bin/bash +eval "$(shellspec - -c) exit 1" + +Mock jf + if [[ "$*" == 'rt curl "api/build'* ]]; then + cat <