Skip to content

Commit

Permalink
feat: add swift support (#46)
Browse files Browse the repository at this point in the history
* feat: add swift support plus fixes

* chore: remove dissused Dockerfile
  • Loading branch information
MrTam authored Apr 8, 2024
1 parent fc70bf3 commit bd583de
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 93 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/push-cocoapods.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Push Cocoapods

on:
on:
push:
branches:
- master

jobs:
jobs:
push:
runs-on: ubuntu-latest
name: Cocoapods Push Demo
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/push-swift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Push Swift

on:
push:
branches:
- master
schedule:
# run every 6 hours
- cron: '0 0,6,12,18 * * *'

jobs:
push:
runs-on: ubuntu-latest
name: Swift Push Demo
steps:
- name: Check out code
uses: actions/checkout@v2

- name: Push
id: push
uses: ./
with:
api-key: ${{ secrets.CLOUDSMITH_API_KEY }}
command: "push"
format: "swift"
name: "cloudsmith-swift-example"
owner: "cloudsmith"
repo: "actions"
republish: "true" # needed ONLY if version is not changing
scope: "cloudsmith"
version: "1.0.0"
file: "test/fixture/cloudsmith-swift-example-1.0.0.zip"
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.9
8 changes: 0 additions & 8 deletions Dockerfile

This file was deleted.

62 changes: 38 additions & 24 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ inputs:
description: "Raw: The name for the package."
required: false
default: none
scope:
description: "Swift: A scope provides a namespace for related packages within the package registry."
required: false
default: none
summary:
description: "Raw: The one-liner synopsis for the package."
required: false
Expand All @@ -87,27 +91,37 @@ inputs:
required: false
default: none
runs:
using: "docker"
image: "Dockerfile"
args:
- -a${{ inputs.api-version }}
- -c${{ inputs.cli-version }}
- -C${{ inputs.skip-install-cli }}
- -k${{ inputs.api-key }}
- -K${{ inputs.command }}
- -f${{ inputs.format }}
- -o${{ inputs.owner }}
- -r${{ inputs.repo }}
- -F${{ inputs.file }}
- -P${{ inputs.republish }}
- -w${{ inputs.wait-interval }}
- -W${{ inputs.no-wait-for-sync }}
- -d${{ inputs.distro }}
- -R${{ inputs.release }}
- -n${{ inputs.name }}
# - -N${{ inputs.symbols-file }} awaiting ENG-1456
- -s${{ inputs.summary }}
- -S${{ inputs.description }}
- -V${{ inputs.version }}
- -p${{ inputs.pom-file }}
- " -- ${{ inputs.extra }}"
using: "composite"
steps:
- name: Setup Python
uses: actions/setup-python@v5
- name: Install cloudsmith-cli and cloudsmith-api ...
if: inputs.skip-install-cli == '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
run: |
bash entrypoint.sh \
-D${{ inputs.description }} \
-k${{ inputs.api-key }} \
-K${{ inputs.command }} \
-f${{ inputs.format }} \
-o${{ inputs.owner }} \
-r${{ inputs.repo }} \
-F${{ inputs.file }} \
-P${{ inputs.republish }} \
-w${{ inputs.wait-interval }} \
-W${{ inputs.no-wait-for-sync }} \
-d${{ inputs.distro }} \
-R${{ inputs.release }} \
-n${{ inputs.name }} \
-N${{ inputs.symbols-file }} \
-s${{ inputs.summary }} \
-S${{ inputs.scope }} \
-V${{ inputs.version }} \
-p${{ inputs.pom-file }} \
-- ${{ inputs.extra }}
53 changes: 17 additions & 36 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ function die {


function setup_options {
options["api_version"]=$DEFAULT
options["cli_version"]=$DEFAULT
options["api_key"]=$DEFAULT
options["command"]="push"
options["format"]=$DEFAULT
Expand All @@ -37,21 +35,19 @@ function setup_options {
options["distro"]=$DEFAULT
options["release"]=$DEFAULT
options["name"]=$DEFAULT
options["scope"]=$DEFAULT
options["summary"]=$DEFAULT
options["description"]=$DEFAULT
options["version"]=$DEFAULT
options["pom_file"]=$DEFAULT
# options["symbols_file"]=$DEFAULT - Awaiting ENG-1456
options["symbols_file"]=$DEFAULT
options["extra"]=$DEFAULT

local raw_opts="$@"
local OPTIND OPT

while getopts ":a:c:C:k:K:f:o:r:F:P:w:W:d:R:n:N:s:S:V:p:" OPT; do
while getopts ":k:K:f:o:r:F:P:w:W:d:R:n:N:s:S:D:V:p:" OPT; do
case $OPT in
a) options["api_version"]="$OPTARG" ;;
c) options["cli_version"]="$OPTARG" ;;
C) options["skip_install_cli"]="$OPTARG" ;;
k) options["api_key"]="$OPTARG" ;;
K) options["command"]="$OPTARG" ;;
f) options["format"]="$OPTARG" ;;
Expand All @@ -64,9 +60,10 @@ function setup_options {
d) options["distro"]="$OPTARG" ;;
R) options["release"]="$OPTARG" ;;
n) options["name"]="$OPTARG" ;;
# N) options["symbols_file"]="$OPTARG" ;; awaiting ENG-1456
N) options["symbols_file"]="$OPTARG" ;;
S) options["scope"]="$OPTARG" ;;
s) options["summary"]="$OPTARG" ;;
S) options["description"]="$OPTARG" ;;
D) options["description"]="$OPTARG" ;;
V) options["version"]="$OPTARG" ;;
p) options["pom_file"]="$OPTARG" ;;
:) die "Option -$OPTARG requires an argument." ;;
Expand Down Expand Up @@ -114,25 +111,6 @@ function check_required_options {
}


function install_api_cli {
if [[ "${options["skip_install_cli"]}" == "true" ]]; then
warn "Skipping Cloudsmith API/CLI installation"
else
echo "Starting Cloudsmith API/CLI installation ..."

check_option_set "${options["cli_version"]}" && {
pip install cloudsmith-cli==${options["cli_version"]}
} || {
pip install cloudsmith-cli
}

check_option_set "${options["api_version"]}" && {
pip install cloudsmith-api==${options["api_version"]}
}
fi
}


function execute_push {
check_required_options format owner repo file

Expand Down Expand Up @@ -172,19 +150,23 @@ function execute_push {
}
;;

# Nuget symbols - awaiting fix ENG-1456
# "nuget")
# check_option_set "${options["symbols_file"]}" && {
# params+=" --symbols-file='${options["symbols_file"]}'"
# }
# ;;
"nuget")
check_option_set "${options["symbols_file"]}" && {
params+=" --symbols-file='${options["symbols_file"]}'"
}
;;

"maven")
check_required_options pom_file
params+=" --pom-file='${options["pom_file"]}'"
;;

"cargo"|"dart"|"docker"|"helm"|"python"|"composer"|"cocoapods"|"npm"|"nuget"|"go")
"swift")
check_required_options scope name version
params+=" --scope='${options["scope"]}' --name='${options["name"]}' --version='${options["version"]}'"
;;

"cargo"|"dart"|"docker"|"helm"|"python"|"composer"|"cocoapods"|"npm"|"go")
# Supported, but no additional options/params
;;

Expand All @@ -211,7 +193,6 @@ function execute_push {

function main {
setup_options "$@"
install_api_cli

case "${options["command"]}" in
"push")
Expand Down
43 changes: 20 additions & 23 deletions test/entrypoint.bats
Original file line number Diff line number Diff line change
Expand Up @@ -97,35 +97,25 @@ function setup_mocks {
assert_output -p "pom_file is required"
}

@test ".cli is installed" {
@test ".name is a required argument, for swift" {
setup_mocks
run $profile_script -f raw -o my-org -r my-repo -F package.raw
assert_success
assert_output -p "EXECUTE pip install cloudsmith-cli"
refute_output -p "EXECUTE pip install cloudsmith-api"
}

@test ".cli is installed, with a specific version" {
setup_mocks
run $profile_script -f raw -o my-org -r my-repo -F package.raw -c 1.0
assert_success
assert_output -p "EXECUTE pip install cloudsmith-cli==1.0"
refute_output -p "EXECUTE pip install cloudsmith-api"
run $profile_script -f swift -o my-org -r my-repo -F package.zip -S my-scope -V 1.0.0
assert_failure
assert_output -p "name is required"
}

@test ".api is installed, with a specific version" {
@test ".scope is a required argument, for swift" {
setup_mocks
run $profile_script -f raw -o my-org -r my-repo -F package.raw -a 1.0
assert_success
assert_output -p "EXECUTE pip install cloudsmith-cli"
assert_output -p "EXECUTE pip install cloudsmith-api==1.0"
run $profile_script -f swift -o my-org -r my-repo -F package.zip -n my-package -V 1.0.0
assert_failure
assert_output -p "scope is required"
}

@test ".cli is skipped if specified" {
@test ".version is a required argument, for swift" {
setup_mocks
run $profile_script -f raw -o my-org -r my-repo -F package.raw -C true
assert_success
refute_output -p "EXECUTE pip install cloudsmith-cli"
run $profile_script -f swift -o my-org -r my-repo -F package.zip -S my-scope -n my-package
assert_failure
assert_output -p "version is required"
}

@test ".execute successful debian push" {
Expand Down Expand Up @@ -179,7 +169,7 @@ function setup_mocks {

@test ".execute successful raw push" {
setup_mocks
run $profile_script -f raw -o my-org -r my-repo -F package.zip -n my-name -s "Some Summary" -S "Some Description" -V 1.0
run $profile_script -f raw -o my-org -r my-repo -F package.zip -n my-name -s "Some Summary" -D "Some Description" -V 1.0
assert_success
assert_output -p "EXECUTE cloudsmith push raw my-org/my-repo package.zip --name=my-name --summary=Some Summary --description=Some Description --version=1.0"
}
Expand Down Expand Up @@ -219,6 +209,13 @@ function setup_mocks {
assert_output -p "EXECUTE cloudsmith push maven my-org/my-repo package.jar --pom-file=package.pom"
}

@test ".execute successful swift push" {
setup_mocks
run $profile_script -f swift -o my-org -r my-repo -F package.zip -n my-package -V 1.0.0 -S my-scope
assert_success
assert_output -p "EXECUTE cloudsmith push swift my-org/my-repo package.zip --scope=my-scope --name=my-package --version=1.0.0"
}

@test ".execute successful other push, but reports unsupported" {
setup_mocks
run $profile_script -f other -o my-org -r my-repo -F package.unk
Expand Down
Binary file added test/fixture/cloudsmith-swift-example-1.0.0.zip
Binary file not shown.

0 comments on commit bd583de

Please sign in to comment.