mirror of
https://code.forgejo.org/actions/forgejo-release.git
synced 2024-11-25 14:11:01 -05:00
test upload & download
This commit is contained in:
parent
89b6ae4da6
commit
ba4ac4e80d
8 changed files with 107 additions and 139 deletions
|
@ -12,13 +12,13 @@ jobs:
|
||||||
image-version: 1.19
|
image-version: 1.19
|
||||||
- name: 001
|
- name: 001
|
||||||
run: |
|
run: |
|
||||||
|
set -ex
|
||||||
export FORGEJO_RUNNER_LOGS="${{ steps.forgejo.outputs.runner-logs }}"
|
export FORGEJO_RUNNER_LOGS="${{ steps.forgejo.outputs.runner-logs }}"
|
||||||
testdata/run.sh push_self http://testuser:admin1234@${{ steps.forgejo.outputs.host-port }} testuser setup-forgejo-release
|
forgejo-test-helper.sh push_self_action http://testuser:admin1234@${{ steps.forgejo.outputs.host-port }} testuser forgejo-release vTest
|
||||||
testdata/run.sh workflow http://testuser:admin1234@${{ steps.forgejo.outputs.host-port }} testuser try-setup-forgejo-release
|
forgejo-test-helper.sh run_workflow testdata/upload-download http://testuser:admin1234@${{ steps.forgejo.outputs.host-port }} testuser upload-download forgejo-release
|
||||||
- name: 002
|
- name: 002
|
||||||
run: |
|
run: |
|
||||||
set -ex
|
set -ex
|
||||||
curl -sS ${{ steps.forgejo.outputs.url }}/api/forgejo/v1/version | grep 1.19
|
|
||||||
export FORGEJO="${{ steps.forgejo.outputs.url }}"
|
export FORGEJO="${{ steps.forgejo.outputs.url }}"
|
||||||
export RELEASETEAMTOKEN="${{ steps.forgejo.outputs.token }}"
|
export RELEASETEAMTOKEN="${{ steps.forgejo.outputs.token }}"
|
||||||
export CI_REPO_OWNER=testuser
|
export CI_REPO_OWNER=testuser
|
||||||
|
|
41
action.yml
41
action.yml
|
@ -1,10 +1,45 @@
|
||||||
name: 'Setup Forgejo release tools'
|
name: 'Forgejo release download and upload'
|
||||||
author: 'Forgejo authors'
|
author: 'Forgejo authors'
|
||||||
description: |
|
description: |
|
||||||
Install dependencies of the forgejo-release-upload and forgejo-release-download
|
Upload or download the assets of a release to a Forgejo instance.
|
||||||
actions.
|
inputs:
|
||||||
|
url:
|
||||||
|
description: 'URL of the Forgejo instance'
|
||||||
|
required: true
|
||||||
|
repo:
|
||||||
|
description: 'owner/project relative to the URL'
|
||||||
|
required: true
|
||||||
|
tag:
|
||||||
|
description: 'Tag of the release'
|
||||||
|
required: true
|
||||||
|
doer:
|
||||||
|
description: 'Forgejo user authoring the upload'
|
||||||
|
token:
|
||||||
|
description: 'Forgejo application token'
|
||||||
|
required: true
|
||||||
|
release-dir:
|
||||||
|
description: 'Directory in whichs release assets are uploaded or downloaded'
|
||||||
|
required: true
|
||||||
|
direction:
|
||||||
|
description: 'Can either be download or upload'
|
||||||
|
required: true
|
||||||
|
verbose:
|
||||||
|
description: 'Increase the verbosity level'
|
||||||
|
default: 'false'
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
steps:
|
steps:
|
||||||
- run: echo "${{ github.action_path }}" >> $GITHUB_PATH
|
- run: echo "${{ github.action_path }}" >> $GITHUB_PATH
|
||||||
shell: bash
|
shell: bash
|
||||||
|
- run: |
|
||||||
|
export FORGEJO="${{ inputs.url }}"
|
||||||
|
export REPO="${{ inputs.repo }}"
|
||||||
|
export TAG="${{ inputs.tag }}"
|
||||||
|
export DOER="${{ inputs.doer }}"
|
||||||
|
export TOKEN="${{ inputs.token }}"
|
||||||
|
export RELEASE_DIR="${{ inputs.release-dir }}"
|
||||||
|
export VERBOSE="${{ inputs.verbose }}"
|
||||||
|
export SHA="${{ github.sha }}"
|
||||||
|
forgejo-release.sh ${{ inputs.direction }}
|
||||||
|
shell: bash
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -ex
|
set -e
|
||||||
|
|
||||||
|
if ${VERBOSE:-false}; then set -x; fi
|
||||||
|
|
||||||
: ${PULL_USER:=forgejo-integration}
|
|
||||||
: ${PUSH_USER:=forgejo}
|
|
||||||
: ${TAG:=${CI_COMMIT_TAG}}
|
|
||||||
: ${FORGEJO:=https://codeberg.org}
|
: ${FORGEJO:=https://codeberg.org}
|
||||||
: ${REPO:=forgejo}
|
: ${REPO:=forgejo-integration/forgejo}
|
||||||
: ${RELEASE_DIR:=dist/release}
|
: ${RELEASE_DIR:=dist/release}
|
||||||
: ${BIN_DIR:=/tmp}
|
: ${BIN_DIR:=$(mktemp -d)}
|
||||||
: ${TEA_VERSION:=0.9.0}
|
: ${TEA_VERSION:=0.9.0}
|
||||||
|
|
||||||
|
|
||||||
setup_tea() {
|
setup_tea() {
|
||||||
if ! test -f $BIN_DIR/tea ; then
|
if ! test -f $BIN_DIR/tea ; then
|
||||||
curl -sL https://dl.gitea.io/tea/$TEA_VERSION/tea-$TEA_VERSION-linux-amd64 > $BIN_DIR/tea
|
curl -sL https://dl.gitea.io/tea/$TEA_VERSION/tea-$TEA_VERSION-linux-amd64 > $BIN_DIR/tea
|
||||||
|
@ -20,33 +18,38 @@ setup_tea() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ensure_tag() {
|
ensure_tag() {
|
||||||
if api GET repos/$PUSH_USER/$REPO/tags/$TAG > /tmp/tag.json ; then
|
if api GET repos/$REPO/tags/$TAG > /tmp/tag.json ; then
|
||||||
local sha=$(jq --raw-output .commit.sha < /tmp/tag.json)
|
local sha=$(jq --raw-output .commit.sha < /tmp/tag.json)
|
||||||
if test "$sha" != "$CI_COMMIT_SHA" ; then
|
if test "$sha" != "$SHA" ; then
|
||||||
cat /tmp/tag.json
|
cat /tmp/tag.json
|
||||||
echo "the tag SHA in the $PUSH_USER repository does not match the tag SHA that triggered the build: $CI_COMMIT_SHA"
|
echo "the tag SHA in the $REPO repository does not match the tag SHA that triggered the build: $SHA"
|
||||||
false
|
false
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
api POST repos/$PUSH_USER/$REPO/tags --data-raw '{"tag_name": "'$CI_COMMIT_TAG'", "target": "'$CI_COMMIT_SHA'"}'
|
api POST repos/$REPO/tags --data-raw '{"tag_name": "'$TAG'", "target": "'$SHA'"}'
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
upload() {
|
upload_release() {
|
||||||
ASSETS=$(ls $RELEASE_DIR/* | sed -e 's/^/-a /')
|
local assets=$(ls $RELEASE_DIR/* | sed -e 's/^/-a /')
|
||||||
echo "${CI_COMMIT_TAG}" | grep -qi '\-rc' && export RELEASETYPE="--prerelease" && echo "Uploading as Pre-Release"
|
local releasetype
|
||||||
echo "${CI_COMMIT_TAG}" | grep -qi '\-test' && export RELEASETYPE="--draft" && echo "Uploading as Draft"
|
echo "${TAG}" | grep -qi '\-rc' && export releasetype="--prerelease" && echo "Uploading as Pre-Release"
|
||||||
test ${RELEASETYPE+false} || echo "Uploading as Stable"
|
echo "${TAG}" | grep -qi '\-test' && export releasetype="--draft" && echo "Uploading as Draft"
|
||||||
|
test ${releasetype+false} || echo "Uploading as Stable"
|
||||||
ensure_tag
|
ensure_tag
|
||||||
anchor=$(echo $CI_COMMIT_TAG | sed -e 's/^v//' -e 's/[^a-zA-Z0-9]/-/g')
|
anchor=$(echo $TAG | sed -e 's/^v//' -e 's/[^a-zA-Z0-9]/-/g')
|
||||||
$BIN_DIR/tea release create $ASSETS --repo $PUSH_USER/$REPO --note "$RELEASENOTES" --tag $CI_COMMIT_TAG --title $CI_COMMIT_TAG ${RELEASETYPE}
|
$BIN_DIR/tea release create $assets --repo $REPO --note "$RELEASENOTES" --tag $TAG --title $TAG ${releasetype}
|
||||||
}
|
}
|
||||||
|
|
||||||
push() {
|
upload() {
|
||||||
setup_api
|
setup_api
|
||||||
setup_tea
|
setup_tea
|
||||||
GITEA_SERVER_TOKEN=$RELEASETEAMTOKEN $BIN_DIR/tea login add --name $RELEASETEAMUSER --url $FORGEJO
|
if ! test "$DOER"; then
|
||||||
upload
|
echo 'missing DOER'
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
GITEA_SERVER_TOKEN=$TOKEN $BIN_DIR/tea login add --name $DOER --url $FORGEJO
|
||||||
|
upload_release
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_api() {
|
setup_api() {
|
||||||
|
@ -61,15 +64,15 @@ api() {
|
||||||
path=$1
|
path=$1
|
||||||
shift
|
shift
|
||||||
|
|
||||||
curl --fail -X $method -sS -H "Content-Type: application/json" -H "Authorization: token $RELEASETEAMTOKEN" "$@" $FORGEJO/api/v1/$path
|
curl --fail -X $method -sS -H "Content-Type: application/json" -H "Authorization: token $TOKEN" "$@" $FORGEJO/api/v1/$path
|
||||||
}
|
}
|
||||||
|
|
||||||
pull() {
|
download() {
|
||||||
setup_api
|
setup_api
|
||||||
(
|
(
|
||||||
mkdir -p $RELEASE_DIR
|
mkdir -p $RELEASE_DIR
|
||||||
cd $RELEASE_DIR
|
cd $RELEASE_DIR
|
||||||
api GET repos/$PULL_USER/$REPO/releases/tags/$TAG > /tmp/assets.json
|
api GET repos/$REPO/releases/tags/$TAG > /tmp/assets.json
|
||||||
jq --raw-output '.assets[] | "\(.name) \(.browser_download_url)"' < /tmp/assets.json | while read name url ; do
|
jq --raw-output '.assets[] | "\(.name) \(.browser_download_url)"' < /tmp/assets.json | while read name url ; do
|
||||||
wget --quiet -O $name $url
|
wget --quiet -O $name $url
|
||||||
done
|
done
|
||||||
|
@ -78,7 +81,7 @@ pull() {
|
||||||
|
|
||||||
|
|
||||||
missing() {
|
missing() {
|
||||||
echo need pull or push argument got nothing
|
echo need upload or download argument got nothing
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
97
testdata/run.sh
vendored
97
testdata/run.sh
vendored
|
@ -1,97 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -ex
|
|
||||||
|
|
||||||
: ${FORGEJO_RUNNER_LOGS:=../setup-forgejo/forgejo-runner.log}
|
|
||||||
DATA=$(dirname $0)
|
|
||||||
DIR=$(mktemp -d)
|
|
||||||
|
|
||||||
trap "rm -fr $DIR" EXIT
|
|
||||||
|
|
||||||
function check_status() {
|
|
||||||
local forgejo="$1"
|
|
||||||
local repo="$2"
|
|
||||||
local sha="$3"
|
|
||||||
|
|
||||||
if ! which jq > /dev/null ; then
|
|
||||||
apt-get install -y -qq jq
|
|
||||||
fi
|
|
||||||
local state=$(curl --fail -sS "$forgejo/api/v1/repos/$repo/commits/$sha/status" | jq --raw-output .state)
|
|
||||||
echo $state
|
|
||||||
test "$state" != "" -a "$state" != "pending" -a "$state" != "running" -a "$state" != "null"
|
|
||||||
}
|
|
||||||
|
|
||||||
function wait_success() {
|
|
||||||
local forgejo="$1"
|
|
||||||
local repo="$2"
|
|
||||||
local sha="$3"
|
|
||||||
|
|
||||||
for i in $(seq 40); do
|
|
||||||
if check_status "$forgejo" "$repo" "$sha"; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
tail $FORGEJO_RUNNER_LOGS
|
|
||||||
sleep 10
|
|
||||||
done
|
|
||||||
if ! test "$(check_status "$forgejo" "$repo" "$sha")" = "success" ; then
|
|
||||||
cat $FORGEJO_RUNNER_LOGS
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function push() {
|
|
||||||
local forgejo="$1"
|
|
||||||
local owner="$2"
|
|
||||||
local workflow="$3"
|
|
||||||
|
|
||||||
local dir="$DIR/$workflow"
|
|
||||||
mkdir -p $dir/.forgejo/workflows
|
|
||||||
sed -e "s|SELF|$forgejo/$owner|" \
|
|
||||||
< $DATA/$workflow.yml > $dir/.forgejo/workflows/$workflow.yml
|
|
||||||
(
|
|
||||||
cd $dir
|
|
||||||
git init
|
|
||||||
git checkout -b main
|
|
||||||
git config user.email root@example.com
|
|
||||||
git config user.name username
|
|
||||||
git add .
|
|
||||||
git commit -m 'initial commit'
|
|
||||||
git remote add origin $forgejo/$owner/$workflow
|
|
||||||
git push --force -u origin main
|
|
||||||
git rev-parse HEAD > SHA
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function workflow() {
|
|
||||||
local forgejo="${1}"
|
|
||||||
local owner="${2}"
|
|
||||||
local workflow="${3}"
|
|
||||||
|
|
||||||
push "$forgejo" "$owner" "$workflow"
|
|
||||||
wait_success "$forgejo" "$owner/$workflow" $(cat $DIR/$workflow/SHA)
|
|
||||||
}
|
|
||||||
|
|
||||||
function push_self() {
|
|
||||||
local forgejo="$1"
|
|
||||||
local owner="$2"
|
|
||||||
local self="$3"
|
|
||||||
|
|
||||||
local dir="$DIR/self"
|
|
||||||
git clone . $dir
|
|
||||||
(
|
|
||||||
cd $dir
|
|
||||||
rm -fr .forgejo .git
|
|
||||||
git init
|
|
||||||
git checkout -b main
|
|
||||||
git remote add origin $forgejo/$owner/$self
|
|
||||||
git config user.email root@example.com
|
|
||||||
git config user.name username
|
|
||||||
git add .
|
|
||||||
git commit -m 'initial commit'
|
|
||||||
git push --force origin main
|
|
||||||
git tag --force vTest HEAD
|
|
||||||
git push --force origin vTest
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
"$@"
|
|
11
testdata/try-setup-forgejo-release.yml
vendored
11
testdata/try-setup-forgejo-release.yml
vendored
|
@ -1,11 +0,0 @@
|
||||||
name: Setup Forgejo Release
|
|
||||||
run-name: ${{ github.actor }} is setting up Forgejo Release
|
|
||||||
on: [push]
|
|
||||||
jobs:
|
|
||||||
setup-forgejo:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- uses: SELF/setup-forgejo-release@vTest
|
|
||||||
- run: |
|
|
||||||
type forgejo-release.sh
|
|
36
testdata/upload-download/.forgejo/workflows/test.yml
vendored
Normal file
36
testdata/upload-download/.forgejo/workflows/test.yml
vendored
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
name: Upload a Forgejo Release
|
||||||
|
on: [push]
|
||||||
|
jobs:
|
||||||
|
setup-forgejo:
|
||||||
|
runs-on: self-hosted
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- id: forgejo
|
||||||
|
uses: https://code.forgejo.org/actions/setup-forgejo@v1
|
||||||
|
with:
|
||||||
|
user: root
|
||||||
|
password: admin1234
|
||||||
|
- id: release-upload
|
||||||
|
uses: SELF@vTest
|
||||||
|
with:
|
||||||
|
direction: upload
|
||||||
|
url: ${{ steps.forgejo.outputs.url }}
|
||||||
|
repo: root/upload-download
|
||||||
|
tag: v1.0
|
||||||
|
doer: root
|
||||||
|
token: ${{ steps.forgejo.outputs.token }}
|
||||||
|
release-dir: upload-dir
|
||||||
|
verbose: true
|
||||||
|
- id: release-download
|
||||||
|
uses: SELF@vTest
|
||||||
|
with:
|
||||||
|
direction: download
|
||||||
|
url: ${{ steps.forgejo.outputs.url }}
|
||||||
|
repo: root/upload-download
|
||||||
|
tag: v1.0
|
||||||
|
doer: root
|
||||||
|
token: ${{ steps.forgejo.outputs.token }}
|
||||||
|
release-dir: download-dir
|
||||||
|
verbose: true
|
||||||
|
- run: |
|
||||||
|
diff -u upload-dir download-dir
|
1
testdata/upload-download/upload-dir/file1.txt
vendored
Normal file
1
testdata/upload-download/upload-dir/file1.txt
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
FILE1
|
1
testdata/upload-download/upload-dir/file2.txt
vendored
Normal file
1
testdata/upload-download/upload-dir/file2.txt
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
FILE2
|
Loading…
Reference in a new issue