diff --git a/README.md b/README.md index 16e2ae3..d872488 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,19 @@ jobs: discord-webhook: ${{ secrets.DISCORD_RELEASE_WEBHOOK }} # optional ``` +A workflow that creates its release with the job's own token (`secrets.GITHUB_TOKEN`) +must announce it itself, as a last step: Gitea starts no workflow for events +the Actions bot causes, so `on: release` never fires for such a release. + +```yaml + - uses: coffey-labs/actions/discourse-release@ + with: + api-key: ${{ secrets.DISCOURSE_RELEASE_KEY }} + tag: ${{ github.ref_name }} +``` + +Both at once is fine: a repo+tag is announced once, whichever runs first. + - The repo must be listed in `discourse-release/release-map.json`, the one place that maps repos to forum categories. - `DISCOURSE_RELEASE_KEY` is an org-level secret (coffey-labs and inbuxa) diff --git a/discourse-release/action.yml b/discourse-release/action.yml index 8609ce1..51d8561 100644 --- a/discourse-release/action.yml +++ b/discourse-release/action.yml @@ -11,6 +11,14 @@ inputs: description: optional Discord webhook URL; when set, the announcement is also posted there required: false default: "" + tag: + description: >- + announce the release with this tag instead of the triggering release + event. Needed in a workflow that creates its release with the job's own + token: Gitea does not start workflows for events the Actions bot causes, + so `on: release` never fires for those releases. + required: false + default: "" forum: description: forum base URL required: false @@ -25,6 +33,8 @@ runs: FORUM: ${{ inputs.forum }} REPO: ${{ github.repository }} EVENT_PATH: ${{ github.event_path }} + TAG: ${{ inputs.tag }} + GITEA_TOKEN: ${{ github.token }} ACTION_PATH: ${{ github.action_path }} MAP: ${{ github.action_path }}/release-map.json run: | diff --git a/discourse-release/announce.sh b/discourse-release/announce.sh index be31168..41ffc89 100755 --- a/discourse-release/announce.sh +++ b/discourse-release/announce.sh @@ -10,6 +10,19 @@ if [ -z "$category_path" ]; then exit 1 fi +if [ -n "${TAG:-}" ]; then + # Called with a tag (a release made by the job's own token): fetch it and + # treat it as the event, so everything below is the same either way. + base="${CI_SERVER_INTERNAL:-$GITHUB_SERVER_URL}" + EVENT_PATH=$(mktemp) + curl -fsS -H "Authorization: token $GITEA_TOKEN" "$base/api/v1/repos/$REPO/releases/tags/$TAG" | + jq '{release: .}' > "$EVENT_PATH" +fi +if [ "$(jq -r '.release.draft // false' "$EVENT_PATH")" = true ]; then + echo "release is a draft; not announcing" + exit 0 +fi + tag=$(jq -r '.release.tag_name' "$EVENT_PATH") # The category id, looked up anonymously (the category is public); the # release-bot key is scoped to creating posts and nothing else.