mirror of
https://code.forgejo.org/actions/forgejo-release.git
synced 2025-04-22 00:48:45 +00:00
Compare commits
No commits in common. "main" and "v2.1.0" have entirely different histories.
15 changed files with 137 additions and 365 deletions
|
@ -1,10 +0,0 @@
|
||||||
root = true
|
|
||||||
|
|
||||||
[*]
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 4
|
|
||||||
tab_width = 4
|
|
||||||
end_of_line = lf
|
|
||||||
charset = utf-8
|
|
||||||
trim_trailing_whitespace = true
|
|
||||||
insert_final_newline = true
|
|
|
@ -6,11 +6,11 @@ jobs:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- id: forgejo
|
- id: forgejo
|
||||||
uses: https://code.forgejo.org/actions/setup-forgejo@v2.0.11
|
uses: https://code.forgejo.org/actions/setup-forgejo@v1
|
||||||
with:
|
with:
|
||||||
user: testuser
|
user: testuser
|
||||||
password: admin1234
|
password: admin1234
|
||||||
image-version: 9
|
image-version: 1.20
|
||||||
|
|
||||||
- name: push self
|
- name: push self
|
||||||
run: |
|
run: |
|
||||||
|
@ -18,38 +18,17 @@ jobs:
|
||||||
|
|
||||||
- name: testdata/upload-download
|
- name: testdata/upload-download
|
||||||
run: |
|
run: |
|
||||||
export LOOP_DELAY=30
|
|
||||||
export FORGEJO_RUNNER_LOGS="${{ steps.forgejo.outputs.runner-logs }}"
|
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 }}"
|
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 }}"
|
||||||
|
|
||||||
set -ex
|
|
||||||
export FORGEJO="${{ steps.forgejo.outputs.url }}"
|
|
||||||
curl --fail -sS $FORGEJO/api/v1/repos/testuser/upload-download/releases/tags/v2.0 > /tmp/v2.json
|
|
||||||
EXPECTED='No shell expansion should on these notes:
|
|
||||||
- $(some_command)
|
|
||||||
- `other_commend`
|
|
||||||
- "double quoted" and '\''single quoted'\'' strings
|
|
||||||
- \backslash escape
|
|
||||||
- !exclamation_mark'
|
|
||||||
test "$EXPECTED" = "$(jq -r .body < /tmp/v2.json)"
|
|
||||||
|
|
||||||
test $(cat /tmp/v2.json | jq -r .hide_archive_links) = false
|
|
||||||
|
|
||||||
curl --fail -sS $FORGEJO/api/v1/repos/testuser/upload-download/releases/tags/v1.0 > /tmp/v1.json
|
|
||||||
cat /tmp/v1.json | jq -r .body | grep '<!--start release-notes-assistant-->'
|
|
||||||
|
|
||||||
test $(cat /tmp/v1.json | jq -r .hide_archive_links) = true
|
|
||||||
|
|
||||||
- name: testdata/upload-download-private
|
- name: testdata/upload-download-private
|
||||||
run: |
|
run: |
|
||||||
export LOOP_DELAY=30
|
|
||||||
export FORGEJO_RUNNER_LOGS="${{ steps.forgejo.outputs.runner-logs }}"
|
export FORGEJO_RUNNER_LOGS="${{ steps.forgejo.outputs.runner-logs }}"
|
||||||
curl -X 'POST' 'http://testuser:admin1234@${{ steps.forgejo.outputs.host-port }}/api/v1/user/repos' -H 'accept: application/json' -H 'Content-Type: application/json' -d '{"name": "upload-download-private","private": true}'
|
curl -X 'POST' 'http://testuser:admin1234@${{ steps.forgejo.outputs.host-port }}/api/v1/user/repos' -H 'accept: application/json' -H 'Content-Type: application/json' -d '{"name": "upload-download-private","private": true}'
|
||||||
forgejo-test-helper.sh run_workflow testdata/upload-download http://testuser:admin1234@${{ steps.forgejo.outputs.host-port }} testuser upload-download-private forgejo-release "${{ steps.forgejo.outputs.token }}"
|
forgejo-test-helper.sh run_workflow testdata/upload-download http://testuser:admin1234@${{ steps.forgejo.outputs.host-port }} testuser upload-download-private forgejo-release "${{ steps.forgejo.outputs.token }}"
|
||||||
|
|
||||||
- name: testdata/nested-upload-download
|
- name: testdata/nested-upload-download
|
||||||
run: |
|
run: |
|
||||||
export LOOP_DELAY=30
|
|
||||||
export FORGEJO_RUNNER_LOGS="${{ steps.forgejo.outputs.runner-logs }}"
|
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 }}"
|
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 }}"
|
||||||
|
|
||||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1 @@
|
||||||
*~
|
*~
|
||||||
.idea
|
|
||||||
|
|
85
README.md
85
README.md
|
@ -1,54 +1,46 @@
|
||||||
# forgejo-release
|
# forgejo-release
|
||||||
|
|
||||||
<!-- action-docs-description source="action.yml" -->
|
<!-- action-docs-description -->
|
||||||
## Description
|
## Description
|
||||||
|
|
||||||
Upload or download the assets of a release to a Forgejo instance.
|
Upload or download the assets of a release to a Forgejo instance.
|
||||||
<!-- action-docs-description source="action.yml" -->
|
<!-- action-docs-description -->
|
||||||
<!-- action-docs-inputs source="action.yml" -->
|
<!-- action-docs-inputs -->
|
||||||
## Inputs
|
## Inputs
|
||||||
|
|
||||||
| name | description | required | default |
|
| parameter | description | required | default |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| `url` | <p>URL of the Forgejo instance</p> | `false` | `${{ env.GITHUB_SERVER_URL }}` |
|
| url | URL of the Forgejo instance | `false` | |
|
||||||
| `repo` | <p>owner/project relative to the URL</p> | `false` | `${{ github.repository }}` |
|
| repo | owner/project relative to the URL | `false` | |
|
||||||
| `tag` | <p>Tag of the release</p> | `false` | `${{ github.ref_name }}` |
|
| tag | Tag of the release | `false` | |
|
||||||
| `title` | <p>Title of the release (defaults to tag)</p> | `false` | `""` |
|
| sha | SHA of the release | `false` | |
|
||||||
| `sha` | <p>SHA of the release</p> | `false` | `${{ github.sha }}` |
|
| token | Forgejo application token | `true` | |
|
||||||
| `token` | <p>Forgejo application token</p> | `false` | `${{ secrets.GITHUB_TOKEN }}` |
|
| release-dir | Directory in whichs release assets are uploaded or downloaded | `true` | |
|
||||||
| `release-dir` | <p>Directory in whichs release assets are uploaded or downloaded</p> | `true` | `""` |
|
| release-notes | Release notes | `false` | |
|
||||||
| `release-notes` | <p>Release notes</p> | `false` | `""` |
|
| direction | Can either be download or upload | `true` | |
|
||||||
| `direction` | <p>Can either be <code>download</code> or <code>upload</code></p> | `true` | `""` |
|
| gpg-private-key | GPG Private Key to sign the release artifacts | `false` | |
|
||||||
| `gpg-private-key` | <p>GPG Private Key to sign the release artifacts</p> | `false` | `""` |
|
| gpg-passphrase | Passphrase of the GPG Private Key | `false` | |
|
||||||
| `gpg-passphrase` | <p>Passphrase of the GPG Private Key</p> | `false` | `""` |
|
| download-retry | Number of times to retry if the release is not ready (default 1) | `false` | |
|
||||||
| `download-retry` | <p>Number of times to retry if the release is not ready (default 1)</p> | `false` | `""` |
|
| verbose | Increase the verbosity level | `false` | false |
|
||||||
| `download-latest` | <p>Download the latest release</p> | `false` | `false` |
|
| override | Override an existing release by the same {tag} | `false` | false |
|
||||||
| `verbose` | <p>Increase the verbosity level</p> | `false` | `false` |
|
| prerelease | Mark Release as Pre-Release | `false` | false |
|
||||||
| `override` | <p>Override an existing release by the same <code>{tag}</code></p> | `false` | `false` |
|
<!-- action-docs-inputs -->
|
||||||
| `prerelease` | <p>Mark Release as Pre-Release</p> | `false` | `false` |
|
|
||||||
| `release-notes-assistant` | <p>Generate release notes with Release Notes Assistant</p> | `false` | `false` |
|
|
||||||
| `hide-archive-link` | <p>Hide the archive links</p> | `false` | `false` |
|
|
||||||
<!-- action-docs-inputs source="action.yml" -->
|
|
||||||
|
|
||||||
## Examples
|
## Example
|
||||||
|
|
||||||
### Upload
|
### Upload
|
||||||
|
|
||||||
Upload the release located in `release-dir` to the release section of a repository (`url` and `repo`):
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
on: [tag]
|
||||||
jobs:
|
jobs:
|
||||||
upload-release:
|
upload-release:
|
||||||
runs-on: docker
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/forgejo-release@v2.6.0
|
- uses: actions/forgejo-release@v1
|
||||||
with:
|
with:
|
||||||
direction: upload
|
direction: upload
|
||||||
url: https://my-forgejo-instance.net
|
url: https://code.forgejo.org
|
||||||
repo: myuser/myrepo
|
|
||||||
token: ${{ secrets.WRITE_TOKEN_TO_MYREPO }}
|
|
||||||
tag: v1.0.0
|
|
||||||
release-dir: dist/release
|
release-dir: dist/release
|
||||||
release-notes: "MY RELEASE NOTES"
|
release-notes: "MY RELEASE NOTES"
|
||||||
```
|
```
|
||||||
|
@ -58,30 +50,21 @@ jobs:
|
||||||
Example downloading the forgejo release v1.21.4-0 into the working directory:
|
Example downloading the forgejo release v1.21.4-0 into the working directory:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
on: [tag]
|
||||||
jobs:
|
jobs:
|
||||||
download-release:
|
download-release:
|
||||||
runs-on: docker
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/forgejo-release@v2.6.0
|
- uses: actions/forgejo-release@v1
|
||||||
with:
|
with:
|
||||||
direction: download
|
direction: download
|
||||||
url: https://my-forgejo-instance.net
|
url: https://code.forgejo.org
|
||||||
repo: myuser/myrepo
|
repo: forgejo/forgejo
|
||||||
token: ${{ secrets.READ_TOKEN_TO_MYREPO }}
|
tag: v1.21.4-0
|
||||||
tag: v1.0.0
|
|
||||||
release-dir: ./ # by default, files are downloaded into dist/release
|
release-dir: ./ # by default, files are downloaded into dist/release
|
||||||
```
|
```
|
||||||
|
|
||||||
### Real world example
|
## Update the README
|
||||||
|
|
||||||
This action is used to [publish](https://code.forgejo.org/forgejo/release-notes-assistant/src/commit/09f2c22d80d5ee655783cfeb2c1d4bab4afec3e4/.forgejo/workflows/release.yml) the release notes assistant assets.
|
With https://github.com/npalm/action-docs `action-docs --update-readme`
|
||||||
|
|
||||||
## Update the `input` section of the README
|
|
||||||
|
|
||||||
Using [action-docs](https://github.com/npalm/action-docs):
|
|
||||||
|
|
||||||
```shell
|
|
||||||
# Edit the action.yml file and run:
|
|
||||||
action-docs --update-readme
|
|
||||||
```
|
|
||||||
|
|
57
action.yml
57
action.yml
|
@ -6,28 +6,22 @@ description: |
|
||||||
inputs:
|
inputs:
|
||||||
url:
|
url:
|
||||||
description: 'URL of the Forgejo instance'
|
description: 'URL of the Forgejo instance'
|
||||||
default: '${{ env.GITHUB_SERVER_URL }}'
|
|
||||||
repo:
|
repo:
|
||||||
description: 'owner/project relative to the URL'
|
description: 'owner/project relative to the URL'
|
||||||
default: '${{ github.repository }}'
|
|
||||||
tag:
|
tag:
|
||||||
description: 'Tag of the release'
|
description: 'Tag of the release'
|
||||||
default: '${{ github.ref_name }}'
|
|
||||||
title:
|
|
||||||
description: 'Title of the release (defaults to tag)'
|
|
||||||
sha:
|
sha:
|
||||||
description: 'SHA of the release'
|
description: 'SHA of the release'
|
||||||
default: '${{ github.sha }}'
|
|
||||||
token:
|
token:
|
||||||
description: 'Forgejo application token'
|
description: 'Forgejo application token'
|
||||||
default: '${{ secrets.GITHUB_TOKEN }}'
|
required: true
|
||||||
release-dir:
|
release-dir:
|
||||||
description: 'Directory in whichs release assets are uploaded or downloaded'
|
description: 'Directory in whichs release assets are uploaded or downloaded'
|
||||||
required: true
|
required: true
|
||||||
release-notes:
|
release-notes:
|
||||||
description: 'Release notes'
|
description: 'Release notes'
|
||||||
direction:
|
direction:
|
||||||
description: 'Can either be `download` or `upload`'
|
description: 'Can either be download or upload'
|
||||||
required: true
|
required: true
|
||||||
gpg-private-key:
|
gpg-private-key:
|
||||||
description: 'GPG Private Key to sign the release artifacts'
|
description: 'GPG Private Key to sign the release artifacts'
|
||||||
|
@ -35,24 +29,15 @@ inputs:
|
||||||
description: 'Passphrase of the GPG Private Key'
|
description: 'Passphrase of the GPG Private Key'
|
||||||
download-retry:
|
download-retry:
|
||||||
description: 'Number of times to retry if the release is not ready (default 1)'
|
description: 'Number of times to retry if the release is not ready (default 1)'
|
||||||
download-latest:
|
|
||||||
description: 'Download the latest release'
|
|
||||||
default: false
|
|
||||||
verbose:
|
verbose:
|
||||||
description: 'Increase the verbosity level'
|
description: 'Increase the verbosity level'
|
||||||
default: false
|
default: 'false'
|
||||||
override:
|
override:
|
||||||
description: 'Override an existing release by the same `{tag}`'
|
description: 'Override an existing release by the same {tag}'
|
||||||
default: false
|
default: 'false'
|
||||||
prerelease:
|
prerelease:
|
||||||
description: 'Mark Release as Pre-Release'
|
description: 'Mark Release as Pre-Release'
|
||||||
default: false
|
default: 'false'
|
||||||
release-notes-assistant:
|
|
||||||
description: 'Generate release notes with Release Notes Assistant'
|
|
||||||
default: false
|
|
||||||
hide-archive-link:
|
|
||||||
description: 'Hide the archive links'
|
|
||||||
default: false
|
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
|
@ -61,36 +46,38 @@ runs:
|
||||||
shell: bash
|
shell: bash
|
||||||
- run: |
|
- run: |
|
||||||
export FORGEJO="${{ inputs.url }}"
|
export FORGEJO="${{ inputs.url }}"
|
||||||
|
if test -z "$FORGEJO"; then
|
||||||
|
export FORGEJO="${{ env.GITHUB_SERVER_URL }}"
|
||||||
|
fi
|
||||||
# A trailing / will mean http://forgejo//api/v1 is used
|
# A trailing / will mean http://forgejo//api/v1 is used
|
||||||
# and it always 401 as of v1.19, because of the double slash
|
# and it always 401 as of v1.19, because of the double slash
|
||||||
FORGEJO=${FORGEJO%%/}
|
FORGEJO=${FORGEJO%%/}
|
||||||
export SCHEME=${FORGEJO%://*}
|
|
||||||
export HOST=${FORGEJO#*://}
|
|
||||||
|
|
||||||
export REPO="${{ inputs.repo }}"
|
export REPO="${{ inputs.repo }}"
|
||||||
|
if test -z "$REPO"; then
|
||||||
|
export REPO="${{ github.repository }}"
|
||||||
|
fi
|
||||||
|
|
||||||
export TAG="${{ inputs.tag }}"
|
export TAG="${{ inputs.tag }}"
|
||||||
|
if test -z "$TAG"; then
|
||||||
export TITLE="${{ inputs.title }}"
|
export TAG="${{ github.ref_name }}"
|
||||||
|
# until https://code.forgejo.org/forgejo/runner/issues/9 is fixed
|
||||||
export DOWNLOAD_LATEST="${{ inputs.download-latest }}"
|
# trim refs/tags/
|
||||||
|
TAG=${TAG##refs/tags/}
|
||||||
|
fi
|
||||||
|
|
||||||
export PRERELEASE="${{ inputs.prerelease }}"
|
export PRERELEASE="${{ inputs.prerelease }}"
|
||||||
|
|
||||||
export RELEASE_NOTES_ASSISTANT="${{ inputs.release-notes-assistant }}"
|
|
||||||
|
|
||||||
export HIDE_ARCHIVE_LINK="${{ inputs.hide-archive-link }}"
|
|
||||||
|
|
||||||
export TOKEN="${{ inputs.token }}"
|
export TOKEN="${{ inputs.token }}"
|
||||||
|
|
||||||
export RELEASE_DIR="${{ inputs.release-dir }}"
|
export RELEASE_DIR="${{ inputs.release-dir }}"
|
||||||
|
|
||||||
export RELEASENOTES=$(cat << 'EOF'
|
export RELEASENOTES="${{ inputs.release-notes }}"
|
||||||
${{ inputs.release-notes }}
|
|
||||||
EOF
|
|
||||||
)
|
|
||||||
|
|
||||||
export SHA="${{ inputs.sha }}"
|
export SHA="${{ inputs.sha }}"
|
||||||
|
if test -z "$SHA"; then
|
||||||
|
export SHA="${{ github.sha }}"
|
||||||
|
fi
|
||||||
|
|
||||||
export OVERRIDE="${{ inputs.override }}"
|
export OVERRIDE="${{ inputs.override }}"
|
||||||
|
|
||||||
|
|
|
@ -7,116 +7,63 @@ if ${VERBOSE:-false}; then set -x; fi
|
||||||
|
|
||||||
: ${FORGEJO:=https://codeberg.org}
|
: ${FORGEJO:=https://codeberg.org}
|
||||||
: ${REPO:=forgejo-integration/forgejo}
|
: ${REPO:=forgejo-integration/forgejo}
|
||||||
: ${TITLE:=$TAG}
|
|
||||||
: ${RELEASE_DIR:=dist/release}
|
: ${RELEASE_DIR:=dist/release}
|
||||||
: ${DOWNLOAD_LATEST:=false}
|
|
||||||
: ${TMP_DIR:=$(mktemp -d)}
|
: ${TMP_DIR:=$(mktemp -d)}
|
||||||
: ${GNUPGHOME:=$TMP_DIR}
|
: ${GNUPGHOME:=$TMP_DIR}
|
||||||
: ${BIN_DIR:=$TMP_DIR}
|
: ${BIN_DIR:=$TMP_DIR}
|
||||||
: ${TEA_VERSION:=0.9.0}
|
: ${TEA_VERSION:=0.9.0}
|
||||||
: ${OVERRIDE:=false}
|
: ${OVERRIDE:=false}
|
||||||
: ${HIDE_ARCHIVE_LINK:=false}
|
|
||||||
: ${RETRY:=1}
|
: ${RETRY:=1}
|
||||||
: ${DELAY:=10}
|
: ${DELAY:=10}
|
||||||
|
|
||||||
TAG_FILE="$TMP_DIR/tag$$.json"
|
|
||||||
|
|
||||||
export GNUPGHOME
|
export GNUPGHOME
|
||||||
|
|
||||||
setup_tea() {
|
setup_tea() {
|
||||||
if ! test -f "$BIN_DIR"/tea; then
|
if ! test -f $BIN_DIR/tea ; then
|
||||||
ARCH=$(dpkg --print-architecture)
|
ARCH=$(dpkg --print-architecture)
|
||||||
curl -sL https://dl.gitea.io/tea/$TEA_VERSION/tea-$TEA_VERSION-linux-"$ARCH" >"$BIN_DIR"/tea
|
curl -sL https://dl.gitea.io/tea/$TEA_VERSION/tea-$TEA_VERSION-linux-$ARCH > $BIN_DIR/tea
|
||||||
chmod +x "$BIN_DIR"/tea
|
chmod +x $BIN_DIR/tea
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
get_tag() {
|
|
||||||
if ! test -f "$TAG_FILE"; then
|
|
||||||
if api GET repos/$REPO/tags/"$TAG" >"$TAG_FILE"; then
|
|
||||||
echo "tag $TAG exists"
|
|
||||||
else
|
|
||||||
echo "tag $TAG does not exists"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
test -s "$TAG_FILE"
|
|
||||||
}
|
|
||||||
|
|
||||||
matched_tag() {
|
|
||||||
if get_tag; then
|
|
||||||
local sha=$(jq --raw-output .commit.sha <"$TAG_FILE")
|
|
||||||
test "$sha" = "$SHA"
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
ensure_tag() {
|
ensure_tag() {
|
||||||
if get_tag; then
|
if api GET repos/$REPO/tags/$TAG > $TMP_DIR/tag.json ; then
|
||||||
if ! matched_tag; then
|
local sha=$(jq --raw-output .commit.sha < $TMP_DIR/tag.json)
|
||||||
cat "$TAG_FILE"
|
if test "$sha" != "$SHA" ; then
|
||||||
|
cat $TMP_DIR/tag.json
|
||||||
echo "the tag SHA in the $REPO repository does not match the tag SHA that triggered the build: $SHA"
|
echo "the tag SHA in the $REPO repository does not match the tag SHA that triggered the build: $SHA"
|
||||||
return 1
|
false
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
create_tag
|
api POST repos/$REPO/tags --data-raw '{"tag_name": "'$TAG'", "target": "'$SHA'"}'
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
create_tag() {
|
|
||||||
api POST repos/$REPO/tags --data-raw '{"tag_name": "'"$TAG"'", "target": "'"$SHA"'"}' >"$TAG_FILE"
|
|
||||||
}
|
|
||||||
|
|
||||||
delete_tag() {
|
|
||||||
if get_tag; then
|
|
||||||
api DELETE repos/$REPO/tags/$TAG
|
|
||||||
rm -f "$TAG_FILE"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
upload_release() {
|
upload_release() {
|
||||||
# assets is defined as a list of arguments, where values may contain whitespace and need to be quoted like this -a "my file.txt" -a "file.txt".
|
local assets=$(ls $RELEASE_DIR/* | sed -e 's/^/-a /')
|
||||||
# It is expanded using "${assets[@]}" which preserves the separation of arguments and not split whitespace containing values.
|
local releasetype
|
||||||
# For reference, see https://github.com/koalaman/shellcheck/wiki/SC2086#exceptions
|
( $PRERELEASE || echo "${TAG}" | grep -qi '\-rc' ) && export releasetype="--prerelease" && echo "Uploading as Pre-Release"
|
||||||
local assets=()
|
test ${releasetype+false} || echo "Uploading as Stable"
|
||||||
for file in "$RELEASE_DIR"/*; do
|
|
||||||
assets=("${assets[@]}" -a "$file")
|
|
||||||
done
|
|
||||||
if $PRERELEASE || echo "${TAG}" | grep -qi '\-rc'; then
|
|
||||||
releaseType="--prerelease"
|
|
||||||
echo "Uploading as Pre-Release"
|
|
||||||
else
|
|
||||||
echo "Uploading as Stable"
|
|
||||||
fi
|
|
||||||
ensure_tag
|
ensure_tag
|
||||||
if ! "$BIN_DIR"/tea release create "${assets[@]}" --repo $REPO --note "$RELEASENOTES" --tag "$TAG" --title "$TITLE" --draft ${releaseType} >&"$TMP_DIR"/tea.log; then
|
anchor=$(echo $TAG | sed -e 's/^v//' -e 's/[^a-zA-Z0-9]/-/g')
|
||||||
if grep --quiet 'Unknown API Error: 500' "$TMP_DIR"/tea.log && grep --quiet services/release/release.go:194 "$TMP_DIR"/tea.log; then
|
if ! $BIN_DIR/tea release create $assets --repo $REPO --note "$RELEASENOTES" --tag $TAG --title $TAG --draft ${releasetype} >& $TMP_DIR/tea.log ; then
|
||||||
|
if grep --quiet 'Unknown API Error: 500' $TMP_DIR/tea.log && grep --quiet services/release/release.go:194 $TMP_DIR/tea.log ; then
|
||||||
echo "workaround v1.20 race condition https://codeberg.org/forgejo/forgejo/issues/1370"
|
echo "workaround v1.20 race condition https://codeberg.org/forgejo/forgejo/issues/1370"
|
||||||
sleep 10
|
sleep 10
|
||||||
"$BIN_DIR"/tea release create "${assets[@]}" --repo $REPO --note "$RELEASENOTES" --tag "$TAG" --title "$TITLE" --draft ${releaseType}
|
$BIN_DIR/tea release create $assets --repo $REPO --note "$RELEASENOTES" --tag $TAG --title $TAG --draft ${releasetype}
|
||||||
else
|
else
|
||||||
cat "$TMP_DIR"/tea.log
|
cat $TMP_DIR/tea.log
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
maybe_use_release_note_assistant
|
|
||||||
release_draft false
|
release_draft false
|
||||||
}
|
}
|
||||||
|
|
||||||
release_draft() {
|
release_draft() {
|
||||||
local state="$1"
|
local state="$1"
|
||||||
|
|
||||||
local id=$(api GET repos/$REPO/releases/tags/"$TAG" | jq --raw-output .id)
|
local id=$(api GET repos/$REPO/releases/tags/$TAG | jq --raw-output .id)
|
||||||
|
api PATCH repos/$REPO/releases/$id --data-raw '{"draft": '$state'}'
|
||||||
api PATCH repos/$REPO/releases/"$id" --data-raw '{"draft": '"$state"', "hide_archive_links": '$HIDE_ARCHIVE_LINK'}'
|
|
||||||
}
|
|
||||||
|
|
||||||
maybe_use_release_note_assistant() {
|
|
||||||
if "$RELEASE_NOTES_ASSISTANT"; then
|
|
||||||
curl --fail -s -S -o rna https://code.forgejo.org/forgejo/release-notes-assistant/releases/download/v1.2.3/release-notes-assistant
|
|
||||||
chmod +x ./rna
|
|
||||||
./rna --storage release --storage-location "$TAG" --forgejo-url "$SCHEME"://placeholder:"$TOKEN"@"$HOST" --repository $REPO --token "$TOKEN" release "$TAG"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sign_release() {
|
sign_release() {
|
||||||
|
@ -125,11 +72,11 @@ sign_release() {
|
||||||
passphrase="--passphrase-file $GPG_PASSPHRASE"
|
passphrase="--passphrase-file $GPG_PASSPHRASE"
|
||||||
fi
|
fi
|
||||||
gpg --import --no-tty --pinentry-mode loopback $passphrase "$GPG_PRIVATE_KEY"
|
gpg --import --no-tty --pinentry-mode loopback $passphrase "$GPG_PRIVATE_KEY"
|
||||||
for asset in "$RELEASE_DIR"/*; do
|
for asset in $RELEASE_DIR/* ; do
|
||||||
if [[ $asset =~ .sha256$ ]] ; then
|
if [[ $asset =~ .sha256$ ]] ; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
gpg --armor --detach-sign --no-tty --pinentry-mode loopback $passphrase <"$asset" >"$asset".asc
|
gpg --armor --detach-sign --no-tty --pinentry-mode loopback $passphrase < $asset > $asset.asc
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,17 +90,15 @@ maybe_override() {
|
||||||
if test "$OVERRIDE" = "false"; then
|
if test "$OVERRIDE" = "false"; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
api DELETE repos/$REPO/releases/tags/"$TAG" >&/dev/null || true
|
api DELETE repos/$REPO/releases/tags/$TAG >& /dev/null || true
|
||||||
if get_tag && ! matched_tag; then
|
api DELETE repos/$REPO/tags/$TAG >& /dev/null || true
|
||||||
delete_tag
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
upload() {
|
upload() {
|
||||||
setup_api
|
setup_api
|
||||||
setup_tea
|
setup_tea
|
||||||
rm -f ~/.config/tea/config.yml
|
rm -f ~/.config/tea/config.yml
|
||||||
GITEA_SERVER_TOKEN=$TOKEN "$BIN_DIR"/tea login add --url $FORGEJO
|
GITEA_SERVER_TOKEN=$TOKEN $BIN_DIR/tea login add --url $FORGEJO
|
||||||
maybe_sign_release
|
maybe_sign_release
|
||||||
maybe_override
|
maybe_override
|
||||||
upload_release
|
upload_release
|
||||||
|
@ -172,14 +117,14 @@ api() {
|
||||||
path=$1
|
path=$1
|
||||||
shift
|
shift
|
||||||
|
|
||||||
curl --fail -X "$method" -sS -H "Content-Type: application/json" -H "Authorization: token $TOKEN" "$@" $FORGEJO/api/v1/"$path"
|
curl --fail -X $method -sS -H "Content-Type: application/json" -H "Authorization: token $TOKEN" "$@" $FORGEJO/api/v1/$path
|
||||||
}
|
}
|
||||||
|
|
||||||
wait_release() {
|
wait_release() {
|
||||||
local ready=false
|
local ready=false
|
||||||
for i in $(seq $RETRY); do
|
for i in $(seq $RETRY); do
|
||||||
if api GET repos/$REPO/releases/tags/"$TAG" | jq --raw-output .draft >"$TMP_DIR"/draft; then
|
if api GET repos/$REPO/releases/tags/$TAG | jq --raw-output .draft > $TMP_DIR/draft; then
|
||||||
if test "$(cat "$TMP_DIR"/draft)" = "false"; then
|
if test "$(cat $TMP_DIR/draft)" = "false"; then
|
||||||
ready=true
|
ready=true
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
@ -198,23 +143,18 @@ wait_release() {
|
||||||
|
|
||||||
download() {
|
download() {
|
||||||
setup_api
|
setup_api
|
||||||
|
wait_release
|
||||||
(
|
(
|
||||||
mkdir -p $RELEASE_DIR
|
mkdir -p $RELEASE_DIR
|
||||||
cd $RELEASE_DIR
|
cd $RELEASE_DIR
|
||||||
if [[ ${DOWNLOAD_LATEST} == "true" ]]; then
|
api GET repos/$REPO/releases/tags/$TAG > $TMP_DIR/assets.json
|
||||||
echo "Downloading the latest release"
|
jq --raw-output '.assets[] | "\(.name) \(.browser_download_url)"' < $TMP_DIR/assets.json | while read name url ; do
|
||||||
api GET repos/$REPO/releases/latest >"$TMP_DIR"/assets.json
|
curl --fail -H "Authorization: token $TOKEN" -o $name -L $url
|
||||||
elif [[ ${DOWNLOAD_LATEST} == "false" ]]; then
|
|
||||||
wait_release
|
|
||||||
echo "Downloading tagged release ${TAG}"
|
|
||||||
api GET repos/$REPO/releases/tags/"$TAG" >"$TMP_DIR"/assets.json
|
|
||||||
fi
|
|
||||||
jq --raw-output '.assets[] | "\(.browser_download_url) \(.name)"' <"$TMP_DIR"/assets.json | while read url name; do # `name` may contain whitespace, therefore, it must be last
|
|
||||||
curl --fail -H "Authorization: token $TOKEN" -o "$name" -L "$url"
|
|
||||||
done
|
done
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
missing() {
|
missing() {
|
||||||
echo need upload or download argument got nothing
|
echo need upload or download argument got nothing
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
{
|
|
||||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
|
||||||
"extends": ["local>actions/renovate-config"],
|
|
||||||
"customManagers": [
|
|
||||||
{
|
|
||||||
"customType": "regex",
|
|
||||||
"description": "update example in README.md",
|
|
||||||
"fileMatch": ["^README.md$"],
|
|
||||||
"matchStrings": [
|
|
||||||
"uses: actions/forgejo-release@(?<currentValue>v\\d+\\.\\d+\\.\\d+)"
|
|
||||||
],
|
|
||||||
"datasourceTemplate": "gitea-tags",
|
|
||||||
"depNameTemplate": "actions/forgejo-release",
|
|
||||||
"versioningTemplate": "semver",
|
|
||||||
"registryUrlTemplate": "https://code.forgejo.org"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
23
testdata/forgejo-release-test.sh
vendored
23
testdata/forgejo-release-test.sh
vendored
|
@ -2,7 +2,6 @@
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
set -ex
|
set -ex
|
||||||
PS4='${BASH_SOURCE[0]}:$LINENO: ${FUNCNAME[0]}: '
|
|
||||||
|
|
||||||
test_teardown() {
|
test_teardown() {
|
||||||
setup_api
|
setup_api
|
||||||
|
@ -39,37 +38,24 @@ test_wait_release() {
|
||||||
! wait_release
|
! wait_release
|
||||||
}
|
}
|
||||||
|
|
||||||
test_create_delete_tag() {
|
|
||||||
delete_tag
|
|
||||||
|
|
||||||
! get_tag
|
|
||||||
create_tag
|
|
||||||
get_tag
|
|
||||||
delete_tag
|
|
||||||
! get_tag
|
|
||||||
}
|
|
||||||
|
|
||||||
test_ensure_tag() {
|
test_ensure_tag() {
|
||||||
delete_tag
|
api DELETE repos/$REPO/tags/$TAG || true
|
||||||
#
|
#
|
||||||
# idempotent
|
# idempotent
|
||||||
#
|
#
|
||||||
ensure_tag
|
ensure_tag
|
||||||
mv $TAG_FILE $TMP_DIR/tag1.json
|
api GET repos/$REPO/tags/$TAG > $TMP_DIR/tag1.json
|
||||||
|
|
||||||
ensure_tag
|
ensure_tag
|
||||||
mv $TAG_FILE $TMP_DIR/tag2.json
|
api GET repos/$REPO/tags/$TAG > $TMP_DIR/tag2.json
|
||||||
|
|
||||||
diff -u $TMP_DIR/tag[12].json
|
diff -u $TMP_DIR/tag[12].json
|
||||||
#
|
#
|
||||||
# sanity check on the SHA of an existing tag
|
# sanity check on the SHA of an existing tag
|
||||||
#
|
#
|
||||||
(
|
(
|
||||||
SHA=12345
|
SHA=12345
|
||||||
! matched_tag
|
|
||||||
! ensure_tag
|
! ensure_tag
|
||||||
)
|
)
|
||||||
delete_tag
|
api DELETE repos/$REPO/tags/$TAG
|
||||||
}
|
}
|
||||||
|
|
||||||
test_maybe_sign_release_no_gpg() {
|
test_maybe_sign_release_no_gpg() {
|
||||||
|
@ -143,7 +129,6 @@ test_run() {
|
||||||
REPO=$user/$project
|
REPO=$user/$project
|
||||||
test_setup $project
|
test_setup $project
|
||||||
test_ensure_tag
|
test_ensure_tag
|
||||||
test_create_delete_tag
|
|
||||||
DELAY=0
|
DELAY=0
|
||||||
test_wait_release_fail
|
test_wait_release_fail
|
||||||
echo "================================ TEST BEGIN"
|
echo "================================ TEST BEGIN"
|
||||||
|
|
|
@ -12,7 +12,7 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- id: forgejo
|
- id: forgejo
|
||||||
uses: https://code.forgejo.org/actions/setup-forgejo@v2.0.11
|
uses: https://code.forgejo.org/actions/setup-forgejo@v1
|
||||||
with:
|
with:
|
||||||
user: testuser
|
user: testuser
|
||||||
password: admin1234
|
password: admin1234
|
||||||
|
@ -35,31 +35,6 @@ jobs:
|
||||||
release-dir: upload-dir
|
release-dir: upload-dir
|
||||||
release-notes: "RELEASE NOTES"
|
release-notes: "RELEASE NOTES"
|
||||||
verbose: true
|
verbose: true
|
||||||
- id: release-upload-override
|
|
||||||
uses: SELF@vTest
|
|
||||||
with:
|
|
||||||
direction: upload
|
|
||||||
url: ${{ steps.forgejo.outputs.url }}
|
|
||||||
repo: testuser/testrepo
|
|
||||||
tag: v1.0
|
|
||||||
sha: ${{ steps.testrepo.outputs.sha }}
|
|
||||||
token: ${{ steps.forgejo.outputs.token }}
|
|
||||||
release-dir: upload-dir
|
|
||||||
release-notes: "RELEASE NOTES"
|
|
||||||
override: true
|
|
||||||
verbose: true
|
|
||||||
- id: release-upload-v2
|
|
||||||
uses: SELF@vTest
|
|
||||||
with:
|
|
||||||
direction: upload
|
|
||||||
url: ${{ steps.forgejo.outputs.url }}
|
|
||||||
repo: testuser/testrepo
|
|
||||||
tag: v2.0
|
|
||||||
sha: ${{ steps.testrepo.outputs.sha }}
|
|
||||||
token: ${{ steps.forgejo.outputs.token }}
|
|
||||||
release-dir: upload-dir-v2
|
|
||||||
release-notes: "RELEASE NOTES V2"
|
|
||||||
verbose: true
|
|
||||||
- id: release-download
|
- id: release-download
|
||||||
uses: SELF@vTest
|
uses: SELF@vTest
|
||||||
with:
|
with:
|
||||||
|
@ -72,17 +47,5 @@ jobs:
|
||||||
verbose: true
|
verbose: true
|
||||||
- run: |
|
- run: |
|
||||||
diff -u upload-dir download-dir
|
diff -u upload-dir download-dir
|
||||||
- id: release-download-latest
|
|
||||||
uses: SELF@vTest
|
|
||||||
with:
|
|
||||||
direction: download
|
|
||||||
url: ${{ steps.forgejo.outputs.url }}
|
|
||||||
repo: testuser/testrepo
|
|
||||||
token: ${{ steps.forgejo.outputs.token }}
|
|
||||||
release-dir: download-dir-v2
|
|
||||||
download-latest: true
|
|
||||||
verbose: true
|
|
||||||
- run: |
|
|
||||||
diff -u upload-dir-v2 download-dir-v2
|
|
||||||
- if: failure()
|
- if: failure()
|
||||||
run: docker logs forgejo
|
run: docker logs forgejo
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
FILE1-V2
|
|
|
@ -1 +0,0 @@
|
||||||
FILE2-V2
|
|
|
@ -18,32 +18,15 @@ jobs:
|
||||||
release-notes: "RELEASE NOTES"
|
release-notes: "RELEASE NOTES"
|
||||||
verbose: true
|
verbose: true
|
||||||
- if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
|
- if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
|
||||||
id: release-upload-override
|
id: release-upload
|
||||||
uses: SELF@vTest
|
uses: SELF@vTest
|
||||||
with:
|
with:
|
||||||
direction: upload
|
direction: upload
|
||||||
tag: v1.0
|
tag: v1.0
|
||||||
token: FORGEJO_TOKEN
|
token: FORGEJO_TOKEN
|
||||||
release-dir: upload-dir
|
release-dir: upload-dir
|
||||||
release-notes-assistant: true
|
release-notes: "RELEASE NOTES"
|
||||||
hide-archive-link: true
|
override: "true"
|
||||||
override: true
|
|
||||||
verbose: true
|
|
||||||
- if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
|
|
||||||
id: release-upload-v2
|
|
||||||
uses: SELF@vTest
|
|
||||||
with:
|
|
||||||
direction: upload
|
|
||||||
tag: v2.0
|
|
||||||
token: FORGEJO_TOKEN
|
|
||||||
release-dir: upload-dir-v2
|
|
||||||
release-notes: |-
|
|
||||||
No shell expansion should on these notes:
|
|
||||||
- $(some_command)
|
|
||||||
- `other_commend`
|
|
||||||
- "double quoted" and 'single quoted' strings
|
|
||||||
- \backslash escape
|
|
||||||
- !exclamation_mark
|
|
||||||
verbose: true
|
verbose: true
|
||||||
- if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
|
- if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
|
||||||
id: release-download
|
id: release-download
|
||||||
|
@ -57,17 +40,3 @@ jobs:
|
||||||
- if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
|
- if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
|
||||||
run: |
|
run: |
|
||||||
diff -u upload-dir download-dir
|
diff -u upload-dir download-dir
|
||||||
- if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
|
|
||||||
id: release-download-latest
|
|
||||||
uses: SELF@vTest
|
|
||||||
with:
|
|
||||||
direction: download
|
|
||||||
token: FORGEJO_TOKEN
|
|
||||||
release-dir: download-dir-v2
|
|
||||||
download-latest: true
|
|
||||||
verbose: true
|
|
||||||
- if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
|
|
||||||
run: |
|
|
||||||
diff -u upload-dir-v2 download-dir-v2
|
|
||||||
- if: failure()
|
|
||||||
run: docker logs forgejo
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
FILE1-V2
|
|
|
@ -1 +0,0 @@
|
||||||
FILE2-V2
|
|
|
@ -1 +0,0 @@
|
||||||
FILE3
|
|
Loading…
Add table
Reference in a new issue