Compare commits

..

14 commits
v2.5.1 ... main

Author SHA1 Message Date
earl-warren
cb5b30e358
Merge pull request 'Update https://code.forgejo.org/actions/setup-forgejo action to v2.0.11' (#49) from renovate/https-code.forgejo.org-actions-setup-forgejo-2.x into main
Some checks failed
/ integration (push) Has been cancelled
Reviewed-on: https://code.forgejo.org/actions/forgejo-release/pulls/49
Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org>
2025-04-13 10:06:09 +00:00
Renovate Bot
f0a9704521
Update https://code.forgejo.org/actions/setup-forgejo action to v2.0.11 2025-04-13 08:31:13 +00:00
earl-warren
73fec07c28
Merge pull request 'chore: teach renovate to update the example version' (#46) from earl-warren/forgejo-release:wip-renovate into main
Reviewed-on: https://code.forgejo.org/actions/forgejo-release/pulls/46
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
2025-04-13 06:46:33 +00:00
Earl Warren
dccbd17bd8
chore: teach renovate to update the example version 2025-04-12 13:33:43 +02:00
earl-warren
bc1ca37df0
Merge pull request 'chore: update the example to refer to v2.6.0' (#45) from wip-readme into main
Some checks are pending
/ integration (push) Waiting to run
Reviewed-on: https://code.forgejo.org/actions/forgejo-release/pulls/45
2025-04-12 11:28:07 +00:00
Earl Warren
a198449381
chore: update the example to refer to v2.6.0
and be explicit about the parameters to improve readability
2025-04-12 13:24:33 +02:00
dorianim
a6e3fdb19e
feat: add default token and document default values (#44)
Some checks failed
/ integration (push) Has been cancelled
This PR adds `${{ secrets.GITHUB_TOKEN }}` as the default value for the token and documents all default values in the readme.
Fixes #43

Co-authored-by: Dorian Zedler <dorian@itsblue.de>
Reviewed-on: https://code.forgejo.org/actions/forgejo-release/pulls/44
Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org>
Co-authored-by: dorianim <dorianim@noreply.code.forgejo.org>
Co-committed-by: dorianim <dorianim@noreply.code.forgejo.org>
2025-04-07 06:35:43 +00:00
earl-warren
73ed2a76a2
Merge pull request 'fix: the tag cache must be deleted when the tag is deleted' (#40) from limiting-factor/forgejo-release:wip-delete into main
Some checks failed
/ integration (push) Has been cancelled
Reviewed-on: https://code.forgejo.org/actions/forgejo-release/pulls/40
Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org>
2025-02-23 23:11:48 +00:00
limiting-factor
1a6975277b fix: the tag cache must be deleted when the tag is deleted
Otherwise it will linger and potentially create problem when
using overrides.
2025-02-23 23:52:48 +01:00
earl-warren
e2af55222e
Merge pull request 'fix: override=true must not needlessly delete a tag' (#39) from limiting-factor/forgejo-release:wip-override into main
Some checks are pending
/ integration (push) Waiting to run
Reviewed-on: https://code.forgejo.org/actions/forgejo-release/pulls/39
Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org>
2025-02-23 20:43:42 +00:00
limiting-factor
0079bcb471 fix: override=true must not needlessly delete a tag
If the tag to be set is exactly the same as the tag that exists, do
not delete it.

When the tag is recreated although it is not necessary, it may trigger
workflows that have already been triggered and send the workflow in a
loop.

- split `get_tag` & `matched_tag` out of ensure_tag
- in case of an override, only delete the tag if it fails `matched_tag`
- trace shell lines to help debug
- add testing
2025-02-23 21:22:31 +01:00
limiting-factor
9d4ddfbaad chore(editorconfig): comply with .editorconfig 2025-02-23 19:02:08 +01:00
Michael Kriese
e4b9180780 Merge pull request 'Replace actions/setup-forgejo action with actions/setup-forgejo v1.0.1' (#36) from renovate/actions-setup-forgejo-replacement into main
Some checks failed
/ integration (push) Has been cancelled
Reviewed-on: https://code.forgejo.org/actions/forgejo-release/pulls/36
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
2024-12-10 05:51:36 +00:00
Renovate Bot
410b453871
Replace actions/setup-forgejo action with actions/setup-forgejo v1.0.1 2024-12-10 00:02:00 +00:00
7 changed files with 154 additions and 102 deletions

View file

@ -6,7 +6,7 @@ jobs:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- id: forgejo - id: forgejo
uses: https://code.forgejo.org/actions/setup-forgejo@v2.0.4 uses: https://code.forgejo.org/actions/setup-forgejo@v2.0.11
with: with:
user: testuser user: testuser
password: admin1234 password: admin1234

View file

@ -10,12 +10,12 @@ Upload or download the assets of a release to a Forgejo instance.
| name | description | required | default | | name | description | required | default |
| --- | --- | --- | --- | | --- | --- | --- | --- |
| `url` | <p>URL of the Forgejo instance</p> | `false` | `""` | | `url` | <p>URL of the Forgejo instance</p> | `false` | `${{ env.GITHUB_SERVER_URL }}` |
| `repo` | <p>owner/project relative to the URL</p> | `false` | `""` | | `repo` | <p>owner/project relative to the URL</p> | `false` | `${{ github.repository }}` |
| `tag` | <p>Tag of the release</p> | `false` | `""` | | `tag` | <p>Tag of the release</p> | `false` | `${{ github.ref_name }}` |
| `title` | <p>Title of the release (defaults to tag)</p> | `false` | `""` | | `title` | <p>Title of the release (defaults to tag)</p> | `false` | `""` |
| `sha` | <p>SHA of the release</p> | `false` | `""` | | `sha` | <p>SHA of the release</p> | `false` | `${{ github.sha }}` |
| `token` | <p>Forgejo application token</p> | `true` | `""` | | `token` | <p>Forgejo application token</p> | `false` | `${{ secrets.GITHUB_TOKEN }}` |
| `release-dir` | <p>Directory in whichs release assets are uploaded or downloaded</p> | `true` | `""` | | `release-dir` | <p>Directory in whichs release assets are uploaded or downloaded</p> | `true` | `""` |
| `release-notes` | <p>Release notes</p> | `false` | `""` | | `release-notes` | <p>Release notes</p> | `false` | `""` |
| `direction` | <p>Can either be <code>download</code> or <code>upload</code></p> | `true` | `""` | | `direction` | <p>Can either be <code>download</code> or <code>upload</code></p> | `true` | `""` |
@ -37,16 +37,18 @@ Upload or download the assets of a release to a Forgejo instance.
Upload the release located in `release-dir` to the release section of a repository (`url` and `repo`): 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: ubuntu-latest runs-on: docker
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: actions/forgejo-release@v2 - uses: actions/forgejo-release@v2.6.0
with: with:
direction: upload direction: upload
url: https://code.forgejo.org url: https://my-forgejo-instance.net
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"
``` ```
@ -56,24 +58,24 @@ 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: ubuntu-latest runs-on: docker
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- uses: actions/forgejo-release@v2 - uses: actions/forgejo-release@v2.6.0
with: with:
direction: download direction: download
url: https://code.forgejo.org url: https://my-forgejo-instance.net
repo: forgejo/forgejo repo: myuser/myrepo
tag: v1.21.4-0 token: ${{ secrets.READ_TOKEN_TO_MYREPO }}
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 ### Real world example
This action is used to [publish](https://code.forgejo.org/forgejo/release-notes-assistant/src/branch/main/.forgejo/workflows/release.yml) the release notes assistant assets. 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.
## Update the `input` section of the README ## Update the `input` section of the README

View file

@ -6,17 +6,21 @@ 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: title:
description: 'Title of the release (defaults to tag)' 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'
required: true default: '${{ secrets.GITHUB_TOKEN }}'
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
@ -57,9 +61,6 @@ 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%%/}
@ -67,17 +68,8 @@ runs:
export HOST=${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 TAG="${{ github.ref_name }}"
# until https://code.forgejo.org/forgejo/runner/issues/9 is fixed
# trim refs/tags/
TAG=${TAG##refs/tags/}
fi
export TITLE="${{ inputs.title }}" export TITLE="${{ inputs.title }}"
@ -99,9 +91,6 @@ runs:
) )
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 }}"

View file

@ -19,6 +19,8 @@ if ${VERBOSE:-false}; then set -x; fi
: ${RETRY:=1} : ${RETRY:=1}
: ${DELAY:=10} : ${DELAY:=10}
TAG_FILE="$TMP_DIR/tag$$.json"
export GNUPGHOME export GNUPGHOME
setup_tea() { setup_tea() {
@ -29,16 +31,46 @@ setup_tea() {
fi 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
}
ensure_tag() { ensure_tag() {
if api GET repos/$REPO/tags/"$TAG" > "$TMP_DIR"/tag.json ; then if get_tag; then
local sha=$(jq --raw-output .commit.sha < "$TMP_DIR"/tag.json) if ! matched_tag; then
if test "$sha" != "$SHA" ; then cat "$TAG_FILE"
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"
false return 1
fi fi
else else
api POST repos/$REPO/tags --data-raw '{"tag_name": "'"$TAG"'", "target": "'"$SHA"'"}' create_tag
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
} }
@ -112,7 +144,9 @@ maybe_override() {
return return
fi fi
api DELETE repos/$REPO/releases/tags/"$TAG" >&/dev/null || true api DELETE repos/$REPO/releases/tags/"$TAG" >&/dev/null || true
api DELETE repos/$REPO/tags/"$TAG" >& /dev/null || true if get_tag && ! matched_tag; then
delete_tag
fi
} }
upload() { upload() {

View file

@ -1,6 +1,18 @@
{ {
"$schema": "https://docs.renovatebot.com/renovate-schema.json", "$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [ "extends": ["local>actions/renovate-config"],
"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"
}
] ]
} }

View file

@ -2,6 +2,7 @@
# 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
@ -38,24 +39,37 @@ 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() {
api DELETE repos/$REPO/tags/$TAG || true delete_tag
# #
# idempotent # idempotent
# #
ensure_tag ensure_tag
api GET repos/$REPO/tags/$TAG > $TMP_DIR/tag1.json mv $TAG_FILE $TMP_DIR/tag1.json
ensure_tag ensure_tag
api GET repos/$REPO/tags/$TAG > $TMP_DIR/tag2.json mv $TAG_FILE $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
) )
api DELETE repos/$REPO/tags/$TAG delete_tag
} }
test_maybe_sign_release_no_gpg() { test_maybe_sign_release_no_gpg() {
@ -129,6 +143,7 @@ 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"

View file

@ -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@v1 uses: https://code.forgejo.org/actions/setup-forgejo@v2.0.11
with: with:
user: testuser user: testuser
password: admin1234 password: admin1234