Skip to content

Commit 77ca8fb

Browse files
committed
BUILD-9877 Rework config-pip action
- Fix usage of overridden HOME directory in tests - Add caching and working-directory parameter - Configure build-number
1 parent 0e0dd2b commit 77ca8fb

File tree

6 files changed

+193
-160
lines changed

6 files changed

+193
-160
lines changed

README.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ for details on how to use it.
2424
- [`config-npm`](#config-npm)
2525
- [`build-npm`](#build-npm)
2626
- [`build-yarn`](#build-yarn)
27+
- [`config-pip`](#config-pip)
2728
- [`promote`](#promote)
2829
- [`pr_cleanup`](#pr_cleanup)
2930
- [`cache`](#cache)
@@ -1058,6 +1059,107 @@ jobs:
10581059
- Support for different branch types (default, maintenance, PR, dogfood, long-lived feature)
10591060
- Comprehensive build logging and error handling
10601061

1062+
## `config-pip`
1063+
1064+
Configure pip build environment with build number, authentication, and default settings.
1065+
1066+
This action configures pip to pull packages from the internal JFrog Artifactory registry instead of the default PyPI.
1067+
1068+
> **Note:** This action automatically calls [`get-build-number`](#get-build-number) to manage the build number.
1069+
> **Note:** This action replaces the deprecated `configure-pipx-repox` action from `sonarqube-cloud-github-actions` repository.
1070+
1071+
### Requirements
1072+
1073+
#### Required GitHub Permissions
1074+
1075+
- `id-token: write`
1076+
- `contents: read`
1077+
1078+
#### Required Vault Permissions
1079+
1080+
- `public-reader` or `private-reader`: Artifactory role for reading dependencies.
1081+
1082+
### Usage
1083+
1084+
```yaml
1085+
permissions:
1086+
id-token: write
1087+
contents: read
1088+
steps:
1089+
- uses: actions/checkout@v5
1090+
- uses: actions/setup-python@v5
1091+
with:
1092+
python-version: 3.12
1093+
- uses: SonarSource/ci-github-actions/config-pip@v1
1094+
- run: pip install pipenv
1095+
```
1096+
1097+
### With Custom Artifactory Reader Role
1098+
1099+
```yaml
1100+
steps:
1101+
- uses: SonarSource/ci-github-actions/config-pip@v1
1102+
with:
1103+
artifactory-reader-role: custom-reader
1104+
```
1105+
1106+
### With Working Directory and Caching Options
1107+
1108+
```yaml
1109+
steps:
1110+
- uses: SonarSource/ci-github-actions/config-pip@v1
1111+
with:
1112+
working-directory: ./python-project
1113+
disable-caching: false
1114+
```
1115+
1116+
### Inputs
1117+
1118+
| Input | Description | Default |
1119+
|---------------------------|-----------------------------------------------------------------------------|----------------------------------------------------------------------|
1120+
| `working-directory` | Relative path under github.workspace to execute the build in | `.` |
1121+
| `artifactory-reader-role` | Suffix for the Artifactory reader role in Vault | `private-reader` for private repos, `public-reader` for public repos |
1122+
| `repox-url` | URL for Repox | `https://repox.jfrog.io` |
1123+
| `repox-artifactory-url` | URL for Repox Artifactory API (overrides repox-url/artifactory if provided) | (optional) |
1124+
| `cache-paths` | Cache paths to use (multiline) | `~/.cache/pip` |
1125+
| `disable-caching` | Whether to disable pip caching entirely | `false` |
1126+
1127+
### Outputs
1128+
1129+
| Output | Description |
1130+
|----------------|---------------------------------------------------------------------------|
1131+
| `BUILD_NUMBER` | The current build number. Also set as environment variable `BUILD_NUMBER` |
1132+
1133+
### Output Environment Variables
1134+
1135+
| Environment Variable | Description |
1136+
|----------------------|--------------------------|
1137+
| `BUILD_NUMBER` | The current build number |
1138+
1139+
See also [`get-build-number`](#get-build-number) output environment variables.
1140+
1141+
### Features
1142+
1143+
- Build number management via [`get-build-number`](#get-build-number)
1144+
- Automatic Artifactory authentication via Vault
1145+
- Auto-detection of reader role based on repository visibility
1146+
- Pip dependency caching with customization options
1147+
- Global pip configuration for all subsequent `pip install` commands
1148+
1149+
### Migration from configure-pipx-repox
1150+
1151+
If you're currently using `SonarSource/sonarqube-cloud-github-actions/configure-pipx-repox@master`, you can replace it with:
1152+
1153+
```yaml
1154+
# Old
1155+
- uses: SonarSource/sonarqube-cloud-github-actions/configure-pipx-repox@master
1156+
1157+
# New
1158+
- uses: SonarSource/ci-github-actions/config-pip@v1
1159+
```
1160+
1161+
Both actions produce the same configuration and are functionally equivalent.
1162+
10611163
## `promote`
10621164

10631165
This action promotes a build in JFrog Artifactory and updates the GitHub status check accordingly.

config-pip/README.md

Lines changed: 0 additions & 77 deletions
This file was deleted.

config-pip/action.yml

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
---
22
name: Config Pip
3-
description: GitHub Action to configure pip build environment with authentication for Artifactory
3+
description: GitHub Action to configure pip build environment with build number, authentication, and default settings
44
inputs:
5+
working-directory:
6+
description: Relative path under github.workspace to execute the build in
7+
default: .
58
artifactory-reader-role:
69
description:
710
Suffix for the Artifactory reader role in Vault. Defaults to `private-reader` for private repositories, and `public-reader`
@@ -13,31 +16,54 @@ inputs:
1316
repox-artifactory-url:
1417
description: URL for Repox Artifactory API (overrides repox-url/artifactory if provided)
1518
default: ''
19+
cache-paths:
20+
description: Cache paths to use (multiline).
21+
default: ~/.cache/pip
22+
disable-caching:
23+
description: Whether to disable pip caching entirely
24+
default: 'false'
1625
host-actions-root:
1726
description: Path to the actions folder on the host (used when called from another local action)
1827
default: ''
1928

29+
outputs:
30+
BUILD_NUMBER:
31+
description: The current build number. Also set as environment variable BUILD_NUMBER
32+
value: ${{ steps.get-build-number.outputs.BUILD_NUMBER }}
33+
2034
runs:
2135
using: composite
2236
steps:
2337
- name: Set local action paths
2438
id: set-path
2539
shell: bash
2640
run: |
27-
echo "::group::Set local action paths"
41+
echo "::group::Fix for using local actions"
2842
echo "GITHUB_ACTION_PATH=$GITHUB_ACTION_PATH"
2943
echo "github.action_path=${{ github.action_path }}"
30-
3144
ACTION_PATH_CONFIG_PIP="${{ github.action_path }}"
32-
HOST_ACTIONS_ROOT="${{ inputs.host-actions-root }}"
33-
if [ -n "$HOST_ACTIONS_ROOT" ]; then
34-
ACTION_PATH_CONFIG_PIP="$HOST_ACTIONS_ROOT/config-pip"
45+
host_actions_root="${{ inputs.host-actions-root }}"
46+
if [ -z "$host_actions_root" ]; then
47+
host_actions_root="$(dirname "$ACTION_PATH_CONFIG_PIP")"
48+
else
49+
ACTION_PATH_CONFIG_PIP="$host_actions_root/config-pip"
3550
fi
36-
3751
echo "ACTION_PATH_CONFIG_PIP=$ACTION_PATH_CONFIG_PIP"
3852
echo "ACTION_PATH_CONFIG_PIP=$ACTION_PATH_CONFIG_PIP" >> "$GITHUB_ENV"
53+
echo "host_actions_root=$host_actions_root" >> "$GITHUB_OUTPUT"
54+
55+
mkdir -p ".actions"
56+
ln -sf "$host_actions_root/get-build-number" .actions/get-build-number
57+
ln -sf "$host_actions_root/cache" .actions/cache
58+
ln -sf "$host_actions_root/shared" .actions/shared
59+
ls -la .actions/*
3960
echo "::endgroup::"
4061
62+
- uses: ./.actions/get-build-number
63+
id: get-build-number
64+
with:
65+
host-actions-root: ${{ steps.set-path.outputs.host_actions_root }}
66+
4167
- name: Set Artifactory reader role
4268
shell: bash
4369
env:
@@ -59,6 +85,7 @@ runs:
5985
- name: Run pip configuration script
6086
id: config
6187
shell: bash
88+
working-directory: ${{ inputs.working-directory }}
6289
env:
6390
# Use custom Artifactory URL if provided, otherwise construct from repox-url
6491
ARTIFACTORY_URL:
@@ -67,3 +94,13 @@ runs:
6794
ARTIFACTORY_USERNAME: ${{ fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_USERNAME }}
6895
ARTIFACTORY_ACCESS_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_ACCESS_TOKEN }}
6996
run: $ACTION_PATH_CONFIG_PIP/config.sh
97+
98+
- name: Cache pip dependencies
99+
uses: ./.actions/cache
100+
if: inputs.disable-caching == 'false'
101+
with:
102+
path: ${{ inputs.cache-paths }}
103+
key: pip-${{ runner.os }}-${{ github.workflow }}-${{ hashFiles(format('{0}/requirements*.txt', inputs.working-directory),
104+
format('{0}/Pipfile.lock', inputs.working-directory), format('{0}/poetry.lock', inputs.working-directory),
105+
format('{0}/pyproject.toml', inputs.working-directory)) }}
106+
restore-keys: pip-${{ runner.os }}-${{ github.workflow }}-

config-pip/config.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ configure_pip() {
3838
echo "Repox host: $repox_host"
3939

4040
# Create pip config directory
41-
mkdir -p ~/.pip
41+
mkdir -p "$HOME/.pip"
4242

4343
# Write pip configuration with Artifactory credentials
4444
cat > ~/.pip/pip.conf <<EOF

run_shell_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22
LANG=
3-
shellspec --kcov spec "$@"
3+
shellspec --kcov spec "$@" --shell bash

0 commit comments

Comments
 (0)