Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/scripts/copr-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash
set -euo pipefail

if [[ ! "${VERSION:-}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo 'Expected a stable release version (vMAJOR.MINOR.PATCH).' >&2
exit 1
fi
if [[ "${DRY_RUN:-}" == true ]]; then
echo "Would build Artalk $VERSION in @artalk/artalk."
exit 0
fi
if [[ "${DRY_RUN:-}" != false ]]; then
echo 'DRY_RUN must be true or false.' >&2
exit 1
fi

# Only send release metadata to the existing Artalk custom webhook.
webhook="${COPR_BUILD_WEBHOOK_URL:-}"
if [[ ! "$webhook" =~ ^https://copr\.fedorainfracloud\.org/webhooks/custom/147364/[a-zA-Z0-9-]+/?$ ]]; then
echo 'Configure COPR_BUILD_WEBHOOK_URL with the Artalk custom webhook base URL.' >&2
exit 1
fi

curl_args=(--fail --silent --show-error --proto '=https' --connect-timeout 15 --max-time 60)
release="https://github.com/ArtalkJS/Artalk/releases/download/$VERSION"
curl "${curl_args[@]}" --location --proto-redir '=https' --head "$release/artalk_ui.tar.gz" > /dev/null

# Do not retry POST: a timed-out request might already have created a build.
payload="$(jq -cn --arg version "$VERSION" '{version: $version}')"
response="$(curl "${curl_args[@]}" --write-out '\n%{http_code}' --header 'Content-Type: application/json' \
--data "$payload" "${webhook%/}/artalk/")"
build_id="${response%$'\n'*}"
build_id="${build_id%$'\n'}"
if [[ "${response##*$'\n'}" != 200 || ! "$build_id" =~ ^[0-9]+$ ]]; then
echo 'COPR did not return a build ID; check webhook history before retrying.' >&2
exit 1
fi

build_url="https://copr.fedorainfracloud.org/coprs/g/artalk/artalk/build/$build_id/"
echo "COPR build: $build_url"
if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then
echo "COPR build for $VERSION: $build_url" >> "$GITHUB_STEP_SUMMARY"
fi

deadline=$((SECONDS + 6600))
while (( SECONDS < deadline )); do
build="$(curl "${curl_args[@]}" --retry 3 \
"https://copr.fedorainfracloud.org/api_3/build/$build_id")"
state="$(jq -er '.state' <<< "$build")"
echo "COPR build $build_id: $state"
case "$state" in
succeeded)
jq -e --arg version "${VERSION#v}-" '
.ownername == "@artalk" and .projectname == "artalk" and
.source_package.name == "artalk" and
(.source_package.version | startswith($version))
' <<< "$build" > /dev/null
exit 0
;;
pending|starting|running|importing|waiting) sleep 30 ;;
*) echo "COPR build did not succeed: $build_url" >&2; exit 1 ;;
esac
done
echo "Timed out waiting for COPR; build may still be running: $build_url" >&2
exit 1
34 changes: 34 additions & 0 deletions .github/workflows/build-rpm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build RPM

on:
workflow_call:
inputs:
version:
required: true
type: string
dry_run:
required: true
type: boolean
secrets:
COPR_BUILD_WEBHOOK_URL:
required: false

permissions:
contents: read

jobs:
copr:
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- name: Checkout workflow scripts
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Build and verify RPM
env:
VERSION: ${{ inputs.version }}
DRY_RUN: ${{ inputs.dry_run }}
COPR_BUILD_WEBHOOK_URL: ${{ secrets.COPR_BUILD_WEBHOOK_URL }}
run: bash .github/scripts/copr-build.sh
22 changes: 21 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ on:
description: "Build items"
type: choice
options:
- "ui,app,docker,rpm"
- "ui,app,docker"
- "ui,app"
- "ui,docker"
- "app,docker"
- "app,rpm"
- ui
- app
- docker
- rpm
default: "ui,app,docker"

permissions:
Expand Down Expand Up @@ -104,9 +107,26 @@ jobs:
permissions:
contents: write

# Build RPM
rpm:
if: |
always() &&
needs.tagging.result == 'success' &&
!contains(fromJSON('["failure", "cancelled"]'), needs.app.result) &&
(inputs.build_items == '' || contains(format(',{0},', inputs.build_items), ',rpm,'))
needs: [tagging, app]
uses: ./.github/workflows/build-rpm.yml
permissions:
contents: read
with:
version: ${{ needs.tagging.outputs.version }}
dry_run: ${{ inputs.dry_run || false }}
secrets:
COPR_BUILD_WEBHOOK_URL: ${{ secrets.COPR_BUILD_WEBHOOK_URL }}

# All builds are complete
done:
needs: [tagging, ui, docker, app]
needs: [tagging, ui, docker, app, rpm]
if: |
always() &&
needs.tagging.result == 'success' &&
Expand Down
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ More exploration:
- **Automated CI on GitHub**:
The automated CI pipeline on GitHub, located in the `.github/workflows` directory, builds the frontend, backend, and Docker images. It publishes Docker images to Docker Hub, handles npm package publishing, and creates GitHub Releases. And also testing the frontend and backend.

### Fedora RPM releases

The release workflow sends the release version to the `@artalk/artalk` COPR project and waits for the build result. COPR uses the scripts on the `dist/fedora` branch and the matching `artalk_ui.tar.gz` release asset. Set `COPR_BUILD_WEBHOOK_URL` to the project's Custom webhook base URL in GitHub Actions secrets.

To build RPMs for an existing release, run **Build and Publish** with its version, select `rpm`, and turn off **Dry run**. This keeps the existing release tag and skips npm and Docker publishing. A dry run does not contact COPR. If a request times out, check COPR's build history before retrying.

The following sections provide more detailed information on the development workflow.

## Project Structure
Expand Down