Compare commits

...

6 Commits

Author SHA1 Message Date
Earl Warren 358b55efd4
wait for a release to no longer be draft before downloading 2023-05-24 01:32:23 +02:00
Earl Warren 56c1c975a3
mark the release as draft until it is ready 2023-05-24 01:09:00 +02:00
Earl Warren fb9e03dc6f
cosmetic change to integration 2023-05-24 01:08:27 +02:00
Earl Warren c77cf483dd
support signing release artifacts 2023-05-23 13:04:53 +02:00
Earl Warren 0037083d2d
cosmetic changes 2023-05-23 13:04:49 +02:00
Earl Warren bb345b780c
LICENSE is MIT 2023-04-01 11:12:56 +02:00
7 changed files with 90 additions and 7 deletions

View File

@ -11,21 +11,21 @@ jobs:
password: admin1234
image-version: 1.19
- name: 001uploadaction
- name: Upload
run: |
forgejo-test-helper.sh push_self_action http://testuser:admin1234@${{ steps.forgejo.outputs.host-port }} testuser forgejo-release vTest
- name: 002upload-download
- name: Upload and download
run: |
export FORGEJO_RUNNER_LOGS="${{ steps.forgejo.outputs.runner-logs }}"
forgejo-test-helper.sh run_workflow testdata/upload-download http://testuser:admin1234@${{ steps.forgejo.outputs.host-port }} testuser upload-download forgejo-release "${{ steps.forgejo.outputs.token }}"
- name: 003nestedupload-download
- name: Nested upload and download
run: |
export FORGEJO_RUNNER_LOGS="${{ steps.forgejo.outputs.runner-logs }}"
forgejo-test-helper.sh run_workflow testdata/nested-upload-download http://testuser:admin1234@${{ steps.forgejo.outputs.host-port }} testuser nested-upload-download forgejo-release "${{ steps.forgejo.outputs.token }}"
- name: 004selftest
- name: Self test
run: |
set -ex
export FORGEJO="${{ steps.forgejo.outputs.url }}"

17
LICENSE Normal file
View File

@ -0,0 +1,17 @@
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -18,6 +18,9 @@ Upload or download the assets of a release to a Forgejo instance.
| release-dir | Directory in whichs release assets are uploaded or downloaded | `true` | |
| release-notes | Release notes | `false` | |
| direction | Can either be download or upload | `true` | |
| gpg-private-key | GPG Private Key to sign the release artifacts | `false` | |
| gpg-passphrase | Passphrase of the GPG Private Key | `false` | |
| download-retry | Number of times to retry if the release is not ready (default 1) | `false` | |
| verbose | Increase the verbosity level | `false` | false |
<!-- action-docs-inputs -->

View File

@ -1,3 +1,4 @@
# SPDX-License-Identifier: MIT
name: 'Forgejo release download and upload'
author: 'Forgejo authors'
description: |
@ -22,6 +23,12 @@ inputs:
direction:
description: 'Can either be download or upload'
required: true
gpg-private-key:
description: 'GPG Private Key to sign the release artifacts'
gpg-passphrase:
description: 'Passphrase of the GPG Private Key'
download-retry:
description: 'Number of times to retry if the release is not ready (default 1)'
verbose:
description: 'Increase the verbosity level'
default: 'false'
@ -39,10 +46,12 @@ runs:
# A trailing / will mean http://forgejo//api/v1 is used
# and it always 401 as of v1.19, because of the double slash
FORGEJO=${FORGEJO%%/}
export REPO="${{ inputs.repo }}"
if test -z "$REPO"; then
export REPO="${{ github.repository }}"
fi
export TAG="${{ inputs.tag }}"
if test -z "$TAG"; then
export TAG="${{ github.ref_name }}"
@ -50,14 +59,21 @@ runs:
# trim refs/tags/
TAG=${TAG##refs/tags/}
fi
export TOKEN="${{ inputs.token }}"
export RELEASE_DIR="${{ inputs.release-dir }}"
export RELEASENOTES="${{ inputs.release-notes }}"
export VERBOSE="${{ inputs.verbose }}"
export SHA="${{ inputs.sha }}"
if test -z "$SHA"; then
export SHA="${{ github.sha }}"
fi
export VERBOSE="${{ inputs.verbose }}"
export RETRY="${{ inputs.download-retry }}"
forgejo-release.sh ${{ inputs.direction }}
shell: bash

View File

@ -1,4 +1,5 @@
#!/bin/bash
# SPDX-License-Identifier: MIT
set -e
@ -9,6 +10,8 @@ if ${VERBOSE:-false}; then set -x; fi
: ${RELEASE_DIR:=dist/release}
: ${BIN_DIR:=$(mktemp -d)}
: ${TEA_VERSION:=0.9.0}
: ${RETRY:=1}
: ${DELAY:=10}
setup_tea() {
if ! test -f $BIN_DIR/tea ; then
@ -34,11 +37,18 @@ upload_release() {
local assets=$(ls $RELEASE_DIR/* | sed -e 's/^/-a /')
local releasetype
echo "${TAG}" | grep -qi '\-rc' && export releasetype="--prerelease" && echo "Uploading as Pre-Release"
echo "${TAG}" | grep -qi '\-test' && export releasetype="--draft" && echo "Uploading as Draft"
test ${releasetype+false} || echo "Uploading as Stable"
ensure_tag
anchor=$(echo $TAG | sed -e 's/^v//' -e 's/[^a-zA-Z0-9]/-/g')
$BIN_DIR/tea release create $assets --repo $REPO --note "$RELEASENOTES" --tag $TAG --title $TAG ${releasetype}
$BIN_DIR/tea release create $assets --repo $REPO --note "$RELEASENOTES" --tag $TAG --title $TAG --draft ${releasetype}
release_draft false
}
release_draft() {
local state="$1"
local id=$(api GET repos/$REPO/releases/tags/$TAG | jq --raw-output .id)
api PATCH repos/$REPO/releases/$id --data-raw '{"draft": '$state'}'
}
upload() {
@ -64,8 +74,30 @@ api() {
curl --fail -X $method -sS -H "Content-Type: application/json" -H "Authorization: token $TOKEN" "$@" $FORGEJO/api/v1/$path
}
wait_release() {
local ready=false
for i in $(seq $RETRY); do
if api GET repos/$REPO/releases/tags/$TAG | jq --raw-output .draft > /tmp/draft; then
if test "$(cat /tmp/draft)" = "false"; then
ready=true
break
fi
echo "release $TAG is still a draft"
else
echo "release $TAG does not exist yet"
fi
echo "waiting $DELAY seconds"
sleep $DELAY
done
if ! $ready ; then
echo "no release for $TAG"
return 1
fi
}
download() {
setup_api
wait_release
(
mkdir -p $RELEASE_DIR
cd $RELEASE_DIR

View File

@ -1,4 +1,5 @@
#!/bin/sh
# SPDX-License-Identifier: MIT
set -ex
@ -31,6 +32,16 @@ test_setup() {
touch $RELEASE_DIR/file-two.txt
}
test_wait_release_fail() {
! wait_release
}
test_wait_release() {
wait_release
release_draft true
! wait_release
}
test_ensure_tag() {
api DELETE repos/$REPO/tags/$TAG || true
#
@ -61,12 +72,15 @@ test_run() {
REPO=$user/$project
test_setup $project
test_ensure_tag
DELAY=0
test_wait_release_fail
echo "================================ TEST BEGIN"
upload
RELEASE_DIR=$pulled
download
diff -r $to_push $pulled
echo "================================ TEST END"
test_wait_release
}
: ${TAG:=v17.8.20-1}

View File

@ -1,3 +1,4 @@
# SPDX-License-Identifier: MIT
name: Upload & Download a Forgejo Release
on: [push]
jobs: