Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various improvements #1

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
44 changes: 29 additions & 15 deletions entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import gnupg
import git
import glob
import shutil
import re
import json
Expand Down Expand Up @@ -63,13 +64,18 @@

github_user = github_repo.split('/')[0]
github_slug = github_repo.split('/')[1]

git_working_folder = github_slug + "-" + gh_branch
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I was having issues with it trying to commit into the same path as the existing checkout was in (which was a different branch).


if os.path.exists(github_slug):
shutil.rmtree(github_slug)
if os.path.exists(git_working_folder):
shutil.rmtree(git_working_folder)

logging.debug("cwd : {}".format(os.getcwd()))
logging.debug(os.listdir())

git_repo = git.Repo.clone_from(
'https://{}@github.com/{}.git'.format(github_token, github_repo),
github_slug,
'https://x-access-token:{}@github.com/{}.git'.format(github_token, github_repo),
git_working_folder,
Comment on lines -71 to +78
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means you can just use a bog standard ${{ secrets.GITHUB_TOKEN }} and you don't have to have a special personal access token or anything.

I can give this a new input name and check for either if you'd rather for backwards compatibility?

Copy link
Owner

@jrandiny jrandiny Apr 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forget why, however I'm pretty sure I have tried using GitHub token and failed (some permission error i forgot). I will try it again when I have the time, maybe GitHub have fix the problem

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)

git_refs = git_repo.remotes.origin.refs
Expand All @@ -86,7 +92,7 @@
logging.debug("cwd : {}".format(os.getcwd()))
logging.debug(os.listdir())

deb_file_handle = DebFile(filename=deb_file_path)
deb_file_handle = DebFile(filename=glob.glob(deb_file_path)[0])
peternewman marked this conversation as resolved.
Show resolved Hide resolved
deb_file_control = deb_file_handle.debcontrol()

current_metadata = {
Expand Down Expand Up @@ -125,10 +131,10 @@

logging.info('-- Importing key --')

key_dir = os.path.join(github_slug, 'public.key')
key_file = os.path.join(git_working_folder, 'public.key')
gpg = gnupg.GPG()

detectPublicKey(gpg, key_dir, key_public)
detectPublicKey(gpg, key_file, key_public)
private_key_id = importPrivateKey(gpg, key_private)

logging.info('-- Done importing key --')
Expand All @@ -137,7 +143,7 @@

logging.info('-- Preparing repo directory --')

apt_dir = os.path.join(github_slug, apt_folder)
apt_dir = os.path.join(git_working_folder, apt_folder)
apt_conf_dir = os.path.join(apt_dir, 'conf')

if not os.path.isdir(apt_dir):
Expand All @@ -163,19 +169,27 @@
logging.info('-- Adding package to repo --')

logging.info('Adding {}'.format(deb_file_path))
os.system(
'reprepro -b {} --export=silent-never includedeb {} {}'.format(
apt_dir,
deb_file_version,
deb_file_path,
)
reprepro_includedeb_cmd = 'reprepro -b {} --export=silent-never includedeb {} {}'.format(
apt_dir,
deb_file_version,
deb_file_path,
)
reprepro_includedeb_exit = os.waitstatus_to_exitcode(os.system(reprepro_includedeb_cmd))
if (reprepro_includedeb_exit != 0) {
logging.error('Command {} failed with {}'.format(reprepro_includedeb_cmd, reprepro_includedeb_exit))
sys.exit(reprepro_includedeb_exit)
}

logging.debug('Signing to unlock key on gpg agent')
gpg.sign('test', keyid=private_key_id, passphrase=key_passphrase)

logging.debug('Export and sign repo')
os.system('reprepro -b {} export'.format(apt_dir))
reprepro_export_cmd = 'reprepro -b {} export'.format(apt_dir)
reprepro_export_exit = os.waitstatus_to_exitcode(os.system(reprepro_export_cmd))
if (reprepro_export_exit != 0) {
logging.error('Command {} failed with {}'.format(reprepro_export_cmd, reprepro_export_exit))
sys.exit(reprepro_export_exit)
}

logging.info('-- Done adding package to repo --')

Expand Down