Skip to content

Commit

Permalink
adds action
Browse files Browse the repository at this point in the history
  • Loading branch information
Kat Cosgrove committed Oct 31, 2019
0 parents commit b3cb51a
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Container image
FROM alpine:3.10

## Copy code from your action repository to the filesystem path `/` in the container
COPY entrypoint.sh /entrypoint.sh

## Disallow storing credentials
ENV JFROG_CLI_OFFER_CONFIG=false

## Install cURL, get the JFrog CLI, and make the script executable
RUN apk update &&\
yes | apk add curl &&\
rm -rf /var/lib/apt/lists/* &&\
curl -fL https://getcli.jfrog.io | sh &&\
mv jfrog /bin &&\
chmod +x entrypoint.sh &&\
mv entrypoint.sh /bin

## When the container starts, run the entrypoint script
ENTRYPOINT ["entrypoint.sh"]
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# JFrog CLI for GitHub Actions v2

This action provides a wrapper around the [JFrog CLI](https://www.jfrog.com/confluence/display/CLI/CLI+for+JFrog+Artifactory). It will execute whatever CLI commands your workflow defines, and can use any of the three authentication methods available to the CLI.

This action only supports [JFrog Artifactory](https://jfrog.com/artifactory/) commands at this time.

## Usage

This action requires several environment variables to operate: the URL for your Artifactory instance, the type of authentication you wish to use, and the credentials for your authentication method.

### Required Variables

| Variable | Value |
| ------------- |:-------------:|
| AUTH | apikey, username, or accesstoken |
| URL | The URL for your Artifactory instance |

### Authentication Variables

| Auth Method | Variable |
| ------------- |:-------------:|
| API Key | APIKEY |
| Access Token | TOKEN |
| Login Credentials | USER and PASS |

**All environment variables other than AUTH should be set as secrets.**

## Example Workflow

The following workflow simply pings your defined Artifactory instance to confirm it is operational. It uses the API key authentication method.

```
name: JFrog CLI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Ping Artifactory
uses: katcosgrove/jfrog-actions@master
with:
cmd: 'ping'
env:
auth: ${{ secrets.AUTH }}
apikey: ${{ secrets.APIKEY }}
url: ${{ secrets.URL }}
```
16 changes: 16 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: 'JFrog CLI for Artifactory'
author: 'Kat Cosgrove'
branding:
icon: 'codepen'
color: 'green'
description: 'Runs a JFrog CLI for Artifactory command.'
image: 'Dockerfile'
inputs:
cmd:
description: 'The command you want to run, without `jfrog rt`'
required: true
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.cmd }}
27 changes: 27 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh

set -e

if [ $auth = "username" ];
then
sh -c "jfrog rt config --interactive=false --enc-password=true --url=$url --user=$user --password=$pass"
elif [ $auth = "apikey" ];
then
sh -c "jfrog rt config --interactive=false --enc-password=true --url=$url --apikey=$apikey"
elif [ $auth = "accesstoken" ];
then
sh -c "jfrog rt config --interactive=false --enc-password=true --url=$url --access-token=$token"
else
echo "Error: Authentication mode must be set!";
fi

for cmd in "$@"; do
echo "Running: '$cmd'"
if sh -c "jfrog rt $cmd"; then
echo "Success!"
else
exit_code=$?
echo "Failure: '$cmd' exited with $exit_code"
exit $exit_code
fi
done

0 comments on commit b3cb51a

Please sign in to comment.