Skip to content

Commit e4f0c05

Browse files
committed
Add Python Action
1 parent c358621 commit e4f0c05

File tree

4 files changed

+73
-16
lines changed

4 files changed

+73
-16
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Container image that runs your code
2+
FROM python:3-slim AS builder
3+
4+
# Copies your code file from your action repository to the filesystem path `/` of the container
5+
ADD . /app
6+
WORKDIR /app
7+
8+
RUN pip install --target=/app requests
9+
10+
# Code file to execute when the docker container starts up (`entrypoint.sh`)
11+
FROM gcr.io/distroless/python3-debian10
12+
COPY --from=builder /app /app
13+
ENV PYTHONPATH /app
14+
CMD ["/app/publish.py"]
Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
name: 'Hello World'
22
description: 'Greet someone and record the time'
33
inputs:
4-
who-to-greet: # id of input
5-
description: 'Who to greet'
6-
required: true
7-
default: 'World'
8-
AppID:
4+
APP_ID:
95
description: 'App ID From Splunkbase'
106
required: true
117
default: '5596'
12-
splunkUser:
8+
SPLUNK_USERNAME:
139
description: 'Splunkbase Username'
1410
required: true
15-
splunkPassword:
11+
SPLUNK_PASSWORD:
1612
description: 'Splunkbase Password'
1713
required: true
18-
outputs:
19-
time: # id of output
20-
description: 'The time we greeted you'
14+
APP_FILE:
15+
description: 'The name of the file, for example "my_package.tar.gz".'
16+
required: true
17+
SPLUNK_VERSION:
18+
description: 'The Splunk version(s) that the release is compatible with. For example, "6.7,7.0".'
19+
required: true
20+
VISIBILITY:
21+
description: 'true = The release is to be visible upon package validation success. false = if the release is to be hidden.'
22+
required: false
23+
default: 'false'
24+
CIM_VERSIONS:
25+
description: 'The CIM version(s) that the release is compatible with. For example, "4.9,4.7".'
26+
required: false
27+
default: ''
2128
runs:
22-
using: 'node16'
23-
main: 'dist/index.js'
29+
using: 'docker'
30+
image: 'Dockerfile'
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import os
2+
import requests
3+
from requests.auth import HTTPBasicAuth
4+
5+
APP_ID= os.environ['APP_ID']
6+
filename = os.environ['APP_FILE']
7+
filepath = os.path.join(os.environ['GITHUB_WORKSPACE'], filename)
8+
SPLUNK_USERNAME = os.environ['SPLUNK_USERNAME']
9+
SPLUNK_PASSWORD = os.environ['SPLUNK_PASSWORD']
10+
SPLUNK_VERSION = os.environ['SPLUNK_VERSION']
11+
12+
api_path = 'https://splunkbase.splunk.com/api/v1/app/{}/new_release'.format(APP_ID)
13+
14+
auth = HTTPBasicAuth(SPLUNK_USERNAME, SPLUNK_PASSWORD)
15+
16+
files = {
17+
'files[]': open(filepath, 'rb'),
18+
'filename': (None, os.path.basename(filepath)),
19+
'splunk_version': (None, SPLUNK_VERSION),
20+
'visibility': (None, 'false'),
21+
'cim_versions': (None, '')
22+
}
23+
24+
response = requests.post(api_path, files=files, auth=auth)
25+
26+
print(response.status_code)
27+
print(response.text)
28+
29+
# if status code is not 200, print the response text
30+
if response.status_code != 200:
31+
response.raise_for_status()
32+
exit(response.status_code)
33+
else:
34+
exit(0)
35+

.github/workflows/testWorkflow.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ jobs:
1313
uses: ./.github/actions/appinspect_publish # Uses an action in the root directory
1414
id: hello
1515
with:
16-
who-to-greet: 'Mona the Octocat'
17-
AppID: '5596'
18-
splunkUser: ${{ secrets.SPLUNKBASE_USER }}
19-
splunkPassword: ${{ secrets.SPLUNKBASE_PASSWORD }}
16+
APP_ID: '5596'
17+
APP_FILE: 'github_app_for_splunk-1.0.0.tar.gz'
18+
SPLUNK_USERNAME: ${{ secrets.SPLUNKBASE_USER }}
19+
SPLUNK_PASSWORD: ${{ secrets.SPLUNKBASE_PASSWORD }}
20+
SPLUNK_VERSION: '8.0,8.1'
2021
# Use the output from the `hello` step
2122
- name: Get the output time
2223
run: echo "The time was ${{ steps.hello.outputs.time }}"

0 commit comments

Comments
 (0)