Skip to content

Commit

Permalink
Dedicated make target to download packages from pre_release and uploa…
Browse files Browse the repository at this point in the history
…d to s3
  • Loading branch information
luckslovez committed Nov 27, 2023
1 parent ad07e9d commit 3a36a33
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/merge-to-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,19 @@ jobs:
# used for signing package stuff
gpg_passphrase: ${{ env.GPG_PASSPHRASE }}
gpg_private_key_base64: ${{ env.GPG_PRIVATE_KEY_BASE64 }}

publish-windows:
name: Publish windows packages to production bucket
needs: get-release-tag
runs-on: ubuntu-latest
steps:
- name: Upload windows packages to s3
uses: ./.github/workflows/run_task.yml
with:
container_make_target: "upload-win-packages"
task_environment:
- name: TAG
value: ${{ needs.get-release-tag.outputs.tag }}
- name: AWS_S3_BUCKET_NAME
value: "logging-fb-windows-packages"
secrets: inherit
6 changes: 6 additions & 0 deletions upload-win-packages/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DEFAULT_GOAL := upload

.PHONY: upload
upload:
pip3 install -r requirements.txt
python3 upload.py
2 changes: 2 additions & 0 deletions upload-win-packages/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
boto3
PyGithub
36 changes: 36 additions & 0 deletions upload-win-packages/upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import logging
import boto3
from botocore.exceptions import ClientError
import os
import urllib.request
from github import Github
from github import Auth


def download_win_packages_from_gh_release(token, tag_name):
auth = Auth.Token(token)
fluent_bit_package_repo = Github(auth).get_repo('newrelic/fluent-bit-package').get_releases()
asset_names = []

for release in fluent_bit_package_repo:
if release.tag_name == tag_name:
for asset in release.get_assets():
if "windows" in asset.name:
urllib.request.urlretrieve(asset.url, asset.name)
asset_names.append(asset.name)

return asset_names

def upload_file(file_name, bucket):
s3_client = boto3.client('s3')
try:
s3_client.upload_file(file_name, bucket, None)
except ClientError as e:
logging.error(e)

if __name__ == "__main__":
token = os.environ['GITHUB_TOKEN']
asset_names = download_win_packages_from_gh_release(token)
bucket_name = os.environ['AWS_S3_BUCKET_NAME']
for asset_name in asset_names:
upload_file(asset_name, 'fluent-bit-package')

0 comments on commit 3a36a33

Please sign in to comment.