-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create jfrog upload artefacts gh action
- Loading branch information
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: 'Upload to JFrog' | ||
description: 'Upload build artefacts to JFrog general registry.' | ||
inputs: | ||
access_token: | ||
description: 'Access token for JFrog service account. Find it in org secrets.' | ||
required: true | ||
user_name: | ||
description: 'Define release tag.' | ||
required: true | ||
registry_url: | ||
description: 'Define release repository.' | ||
required: true | ||
artefacts_patterns: | ||
description: 'Define patterns for files which are going to be uploaded - pytyhon regex.' | ||
required: false | ||
default: '*' | ||
action_shell: | ||
required: false | ||
default: 'bash' | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- uses: actions/setup-python@v4 | ||
if: ${{ runner.environment == 'github-hosted' }} | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: 'Upload artefacts' | ||
run: | | ||
python3 ${{ github.action_path }}/artefacts2jfrog.py | ||
shell: ${{ inputs.action_shell }} | ||
env: | ||
ARTEFACTS_PATTERNS: ${{ inputs.artefacts_patterns }} | ||
REGISTRY_URL: ${{ inputs.registry_url }} | ||
ACCESS_TOKEN: ${{ inputs.access_token }} | ||
SERVICE_ACCOUNT: ${{ inputs.user_name }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import re | ||
import requests | ||
import subprocess | ||
import hashlib | ||
import glob | ||
|
||
|
||
patterns = os.environ["ARTEFACTS_PATTERNS"].split() | ||
print(f"Looking for following patterns \n {patterns}") | ||
|
||
def base_path(path_): | ||
while 1: | ||
path_ = os.path.split(path_)[0] | ||
if "*" not in path_: | ||
break | ||
return path_ | ||
|
||
def find_artefacts(): | ||
artefacts = list() | ||
for pattern in patterns: | ||
for file_path in glob.iglob(pattern): | ||
artefacts += [file_path] | ||
|
||
return artefacts | ||
|
||
def upload_artefacts(file_path): | ||
jfrog_url = os.environ["REGISTRY_URL"] | ||
jfrog_token = os.environ["ACCESS_TOKEN"] | ||
jfrog_user = os.environ["SERVICE_ACCOUNT"] | ||
|
||
file_name = os.path.split(file_path)[1] | ||
# add check of sha for downloads | ||
headers = {'content_type': 'application/octet-stream'} | ||
jfrog_url_ = os.path.join(jfrog_url, file_name) | ||
|
||
with open(file_path, 'rb') as f: | ||
r = requests.put(jfrog_url_, | ||
auth=(jfrog_user, | ||
jfrog_token), | ||
data=f, | ||
headers=headers) | ||
if r.status_code != 201: | ||
print("Something went wrong! Check response:") | ||
print(r.json()) | ||
raise IOError("Download error") | ||
else: | ||
print(f"#### {file_name} download url:\n{r.json()['downloadUri']}") | ||
|
||
|
||
if __name__ == '__main__': | ||
artefacts_ = find_artefacts() | ||
print("Found following artefacts:") | ||
print(artefacts_) | ||
for file_path in artefacts_: | ||
upload_artefacts(file_path) |