Skip to content

Commit

Permalink
CI: Support dry-run uploads, to test SFTP connection
Browse files Browse the repository at this point in the history
  • Loading branch information
aperezdc committed Nov 6, 2023
1 parent 65ef3a9 commit fd574b9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
default: 'on-merge'
options:
- 'on-merge'
- 'dry-run'
- 'skip'
- 'yes'
pull_request:
Expand Down Expand Up @@ -47,11 +48,12 @@ jobs:
path: ./wpewebkit-android-${{ matrix.target }}*
if-no-files-found: error
- name: Upload packages to wpewebkit.org
if: ${{ inputs.upload_packages == 'yes' || (github.event.pull_request.merged == true && inputs.upload_packages == 'on-merge') }}
if: ${{ inputs.upload_packages == 'yes' || inputs.upload_packages == 'dry-run' || (github.event.pull_request.merged == true && inputs.upload_packages == 'on-merge') }}
run: |
python3 ./.github/workflows/upload.py "./wpewebkit-android-${{ matrix.target }}*" || \
echo "**:warning: WARNING :warning:** Cannot upload ./wpewebkit-android-${{ matrix.target }}... files to wpewebkit.org" >> $GITHUB_STEP_SUMMARY
exit 0
env:
UPLOAD_DRY_RUN: ${{ inputs.upload_packages == 'dry-run' }}
UPLOAD_KEY_PASSWD: ${{ secrets.UPLOAD_KEY_PASSWD }}
UPLOAD_SSH_KNOWN_HOSTS: ${{ secrets.UPLOAD_SSH_KNOWN_HOSTS }}
17 changes: 15 additions & 2 deletions .github/workflows/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import os
import sys

dry_run = os.environ.get("UPLOAD_DRY_RUN", "false").lower().strip() in ("1", "yes", "true")
log = logging.getLogger(__name__)

_PKGNAME_REGEX = re.compile(r"""
Expand Down Expand Up @@ -124,7 +125,10 @@ async def upload_tarball(sftp, path: Path, progress: bool):
remotedir = f"wpewebkit/android/bootstrap/{spec.version}"
print("Remote location:", remotedir)
if not await sftp.isdir(remotedir):
await sftp.mkdir(remotedir)
if dry_run:
log.info("dry-run: Skipped target directory creation")
else:
await sftp.mkdir(remotedir)

if spec.datecode:
log.warn("Package '%s' already has a datecode, continuing anyway", path)
Expand All @@ -142,6 +146,10 @@ async def upload_tarball(sftp, path: Path, progress: bool):
print("Remote symlink:", symlink_name)
print("Remote filename:", str(spec))

if dry_run:
log.info("dry-run: Skipped package upload and symlink update.")
return

progress_handler = None
if progress:
progress_handler = show_progress
Expand All @@ -155,7 +163,12 @@ async def upload_tarball(sftp, path: Path, progress: bool):


async def main(path, progress):
logging.basicConfig(level=logging.WARN)
if dry_run:
logging.basicConfig(level=logging.INFO)
log.info("Note: UPLOAD_DRY_RUN was set, SFTP connection still used "
"but packages will NOT be uploaded.")
else:
logging.basicConfig(level=logging.WARN)
files = [path]
if "*" in path:
files = glob(path)
Expand Down

0 comments on commit fd574b9

Please sign in to comment.