diff options
-rw-r--r-- | .github/workflows/deploy_snapshot.yml | 8 | ||||
-rwxr-xr-x | scripts/deploy-snapshot.sh | 56 |
2 files changed, 50 insertions, 14 deletions
diff --git a/.github/workflows/deploy_snapshot.yml b/.github/workflows/deploy_snapshot.yml index b8bfbbc8..e8f41046 100644 --- a/.github/workflows/deploy_snapshot.yml +++ b/.github/workflows/deploy_snapshot.yml @@ -11,6 +11,8 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3.0.0 + with: + fetch-depth: 0 - name: Set up JDK uses: actions/setup-java@v3.0.0 @@ -40,9 +42,3 @@ jobs: - name: Deploy snapshot run: scripts/deploy-snapshot.sh - env: - ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }} - SSH_USERNAME: ${{ secrets.SSH_USERNAME }} - SERVER_ADDRESS: ${{ secrets.SERVER_ADDRESS }} - SERVER_DESTINATION: ${{ secrets.SERVER_DESTINATION }} - SSH_PORT: ${{ secrets.SSH_PORT }} diff --git a/scripts/deploy-snapshot.sh b/scripts/deploy-snapshot.sh index 0f10d9eb..5a8c846f 100755 --- a/scripts/deploy-snapshot.sh +++ b/scripts/deploy-snapshot.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash # # Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. # SPDX-License-Identifier: GPL-3.0-only @@ -6,10 +6,50 @@ set -ex -export SSHDIR="$HOME/.ssh" -mkdir -p "$SSHDIR" -echo "$ACTIONS_DEPLOY_KEY" > "$SSHDIR/key" -chmod 600 "$SSHDIR/key" -export SERVER_DEPLOY_STRING="$SSH_USERNAME@$SERVER_ADDRESS:$SERVER_DESTINATION" -cd "$GITHUB_WORKSPACE/app/outputs/" -rsync -ahvcr --omit-dir-times --progress --delete --no-o --no-g -e "ssh -i $SSHDIR/key -o StrictHostKeyChecking=no -p $SSH_PORT" . "$SERVER_DEPLOY_STRING" +LATEST_TAG="latest" +CURRENT_REV="$(git rev-parse --short HEAD)" +ASSET_DIRECTORY="${GITHUB_WORKSPACE}/app/outputs" + +function overwrite_local_tag() { + git tag -f "${LATEST_TAG}" +} + +function overwrite_remote_tag() { + git push -f origin "${LATEST_TAG}" +} + +function has_release() { + gh release view "${LATEST_TAG}" + echo "$?" +} + +function delete_release() { + gh release delete --yes "${LATEST_TAG}" +} + +function create_rev_file() { + pushd "${ASSET_DIRECTORY}" + echo "${CURRENT_REV}" | tee rev-hash.txt + popd +} + +function create_release() { + local CHANGELOG_FILE + CHANGELOG_FILE="$(mktemp)" + echo "Latest release for APS from revision ${CURRENT_REV}" | tee "${CHANGELOG_FILE}" + pushd "${ASSET_DIRECTORY}" + gh release create --title "Latest snapshot build" -F "${CHANGELOG_FILE}" "${LATEST_TAG}" ./* + popd +} + +overwrite_local_tag + +if [[ "$(has_release)" -eq 0 ]]; then + delete_release +fi + +create_rev_file + +overwrite_remote_tag + +create_release |