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

CENG-250: Add an option to utilise executable for Cloudsmith CLI instead of installing python #57

Merged
merged 21 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/generate-exec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Generate Executable

on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install pip
run: python -m pip install --upgrade pip

- name: Install shiv
run: pip install shiv

- name: Generate Executable
run: shiv -c cloudsmith -o ./cloudsmith cloudsmith-cli

- name: Commit and push if it's updated
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add cloudsmith
git diff --quiet && git diff --staged --quiet || (git commit -m "Update executable"; git push)
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,27 @@

Push packages easily to your [Cloudsmith](https://cloudsmith.com) repositories, using the [Cloudsmith CLI](https://pypi.org/project/cloudsmith-cli/).

## Cloudsmith CLI
## Cloudsmith CLI and Executable

This action uses the Cloudsmith CLI and intends to be as similar
to its structure and terminology as possible.
This action now supports both the Cloudsmith CLI and the new Cloudsmith executable. The Cloudsmith executable allows you to use Cloudsmith without needing to install it via pip, making it easier to integrate into your workflows.

From v0.6.9, we default the action to use the executable instead of having to install python, if you wish to use the old workflow, you can do so by specifying `executable: "false"`. This will attempt to download python and use pip to install the Cloudsmith-cli instead.

```yaml
...
- name: Push
id: push
uses: cloudsmith-io/action@master
with:
api-key: ${{ secrets.CLOUDSMITH_API_KEY }}
command: "push"
format: "maven"
owner: "cloudsmith"
repo: "actions"
republish: "true"
file: "test/fixture/cloudsmith-maven-example-1.0.0.jar"
executable: "false" # Add this to use pip instead
```

**Supported:**

Expand Down
10 changes: 9 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,30 @@ inputs:
description: "The tags for the package, comma seperated"
required: false
default: none
use-executable:
description: "All: If true, the pre-packaged executable will be used instead of Python install and pip install."
required: false
default: "true"
runs:
using: "composite"
steps:
- name: Setup Python
if: inputs.use-executable == 'false'
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install cloudsmith-cli and cloudsmith-api ...
if: inputs.skip-install-cli == 'false'
if: inputs.skip-install-cli == 'false' && inputs.use-executable == 'false'
shell: bash
run: |
pip install \
cloudsmith-api${{ inputs.api-version != 'none' && format('=={0}', inputs.api-version) || ''}} \
cloudsmith-cli${{ inputs.cli-version != 'none' && format('=={0}', inputs.cli-version) || ''}} \
- name: Run Entrypoint
shell: bash
env:
USE_EXECUTABLE: ${{ inputs.use-executable }}
GITHUB_ACTION_PATH: ${{ github.action_path }}
run: |
bash ${{ github.action_path }}/entrypoint.sh \
-k ${{ inputs.api-key }} \
Expand Down
Binary file added cloudsmith
Binary file not shown.
6 changes: 5 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ function execute_push {
extra="${options["extra"]}"
}

local request="cloudsmith push ${options["action"]} ${options["format"]} $context ${options["file"]} $params $extra $tags"
local executable="cloudsmith"
if [ "$USE_EXECUTABLE" = "true" ]; then
executable="${GITHUB_ACTION_PATH}/cloudsmith"
fi
local request="$executable push ${options["action"]} ${options["format"]} $context ${options["file"]} $params $extra $tags"
BartoszBlizniak marked this conversation as resolved.
Show resolved Hide resolved
echo $request
eval $request
}
Expand Down