name: Site Pack on: push: branches: - main repository_dispatch: types: - build-pack workflow_dispatch: inputs: force: description: "Force rebuild even if nothing changed" required: false default: "false" jobs: pack: runs-on: shell env: GITEA_API: ${{ gitea.api_url }} GITEA_REPO: ${{ gitea.repository }} TOKEN: ${{ secrets.GITEA_TOKEN }} PACK_VERSION: pack-$(date +%Y%m%d-%H%M) steps: - name: Setup run: | set -e exec 2>&1 echo "=== Building site pack ${PACK_VERSION} ===" WORK="/tmp/pack-build" rm -rf "$WORK" && mkdir -p "$WORK/src" "$WORK/out" echo "WORK=$WORK" >> "$GITHUB_ENV" - name: Pull CMS (this repo) run: | set -e git clone --depth 1 "${{ gitea.server_url }}/${{ gitea.repository }}.git" "$WORK/src/cms" 2>/dev/null \ || git -C "$WORK/src/cms" pull --ff-only 2>/dev/null echo "cms: $(git -C "$WORK/src/cms" rev-parse --short HEAD 2>/dev/null)" | tee -a "$WORK/components.txt" - name: Pull Catalogus run: | set -e git clone --depth 1 https://gitlab.epicnabbo.nl/remco/Epicnabbo-Catalogus-Updated-Daily.git "$WORK/src/catalogus" 2>/dev/null \ || git -C "$WORK/src/catalogus" pull --ff-only 2>/dev/null echo "catalogus: $(git -C "$WORK/src/catalogus" rev-parse --short HEAD 2>/dev/null)" | tee -a "$WORK/components.txt" - name: Pull Nitro-V3 run: | set -e git clone --depth 1 https://github.com/duckietm/Nitro-V3.git "$WORK/src/nitro" 2>/dev/null \ || git -C "$WORK/src/nitro" pull --ff-only 2>/dev/null echo "nitro: $(git -C "$WORK/src/nitro" rev-parse --short HEAD 2>/dev/null)" | tee -a "$WORK/components.txt" - name: Pull Nitro-Render-V3 run: | set -e git clone --depth 1 https://github.com/duckietm/Nitro_Render_V3.git "$WORK/src/render" 2>/dev/null \ || git -C "$WORK/src/render" pull --ff-only 2>/dev/null echo "render: $(git -C "$WORK/src/render" rev-parse --short HEAD 2>/dev/null)" | tee -a "$WORK/components.txt" - name: Pull Polaris Emulator run: | set -e git clone --depth 1 https://github.com/duckietm/Polaris-Emulator.git "$WORK/src/emulator" 2>/dev/null \ || git -C "$WORK/src/emulator" pull --ff-only 2>/dev/null echo "emulator: $(git -C "$WORK/src/emulator" rev-parse --short HEAD 2>/dev/null)" | tee -a "$WORK/components.txt" - name: Build Nitro-V3 client run: | set -e cd "$WORK/src/nitro" yarn install --frozen-lockfile --prefer-offline 2>&1 || yarn install 2>&1 yarn build mkdir -p "$WORK/out/nitro" cp -r dist/* "$WORK/out/nitro/" 2>/dev/null || true echo "nitro built" | tee -a "$WORK/build.txt" - name: Build Nitro-Render-V3 run: | set -e cd "$WORK/src/render" yarn install --frozen-lockfile --prefer-offline 2>&1 || yarn install 2>&1 mkdir -p "$WORK/out/render" cp -r . "$WORK/out/render/" 2>/dev/null || true rm -rf "$WORK/out/render/node_modules" 2>/dev/null || true echo "render built" | tee -a "$WORK/build.txt" - name: Build Polaris Emulator run: | set -e cd "$WORK/src/emulator" mvn package -q -T 1C -o -Dmaven.test.skip=true 2>&1 \ || mvn package -q -T 1C -Dmaven.test.skip=true 2>&1 mkdir -p "$WORK/out/emulator" find target -maxdepth 1 -name 'Polaris-*-jar-with-dependencies.jar' -exec cp {} "$WORK/out/emulator/" \; 2>/dev/null || true echo "emulator built" | tee -a "$WORK/build.txt" - name: Assemble Pack run: | set -e cd "$WORK/out" cp -r "$WORK/src/cms" "$WORK/out/cms" 2>/dev/null || true rm -rf "$WORK/out/cms/.git" "$WORK/out/cms/node_modules" 2>/dev/null || true cp -r "$WORK/src/catalogus" "$WORK/out/catalogus" 2>/dev/null || true rm -rf "$WORK/out/catalogus/.git" 2>/dev/null || true # Manifest of exact component versions cp "$WORK/components.txt" "$WORK/out/COMPONENTS.txt" echo "Built at $(date -u)" > "$WORK/out/BUILD_INFO.txt" cat "$WORK/components.txt" >> "$WORK/out/BUILD_INFO.txt" PACK_FILE="/tmp/${PACK_VERSION}.tar.gz" tar -czf "$PACK_FILE" -C "$WORK/out" . echo "PACK_FILE=$PACK_FILE" >> "$GITHUB_ENV" echo "Pack created: $(du -h "$PACK_FILE" | cut -f1)" - name: Build Changelog run: | set -e BARE="/docker/gitea/gitea/git/repositories/remco/epicnext-cms.git" PREV="$(git -C "$BARE" tag --list 'pack-*' --sort=-creatordate | head -1 || echo '')" if [ -n "$PREV" ]; then CMS_LOG="$(git -C "$BARE" log --oneline --no-decorate "${PREV}..HEAD" 2>/dev/null || echo "")" else CMS_LOG="$(git -C "$BARE" log --oneline --no-decorate -5 2>/dev/null || echo "")" fi { echo "## Site Pack ${PACK_VERSION}" echo "" echo "### Component versions" echo '```' cat "$WORK/components.txt" echo '```' echo "" echo "### CMS changes since ${PREV:-none}" echo '```' echo "${CMS_LOG:-none}" echo '```' } > /tmp/pack-body.md cat /tmp/pack-body.md - name: Create Release + Upload Pack run: | set -e BODY="$(jq -Rs '.' < /tmp/pack-body.md)" PAYLOAD="$(jq -n --arg tag "${PACK_VERSION}" --arg name "${PACK_VERSION}" --arg body "$BODY" '{tag_name: $tag, name: $name, body: $body, draft: false, prerelease: false}')" T="${TOKEN:-$GITEA_TOKEN}" HTTP="$(curl -s -w '%{http_code}' -o /tmp/pack-rel.json \ -X POST "${GITEA_API}/repos/${GITEA_REPO}/releases" \ -H "Authorization: token ${T}" -H "Content-Type: application/json" -d "$PAYLOAD")" if [ "${HTTP}" = "409" ]; then REL_ID="$(curl -sf "${GITEA_API}/repos/${GITEA_REPO}/releases" -H "Authorization: token ${T}" | jq -r ".[] | select(.tag_name==\"${PACK_VERSION}\") | .id")" HTTP="$(curl -s -w '%{http_code}' -o /tmp/pack-rel.json -X PATCH "${GITEA_API}/repos/${GITEA_REPO}/releases/${REL_ID}" -H "Authorization: token ${T}" -H "Content-Type: application/json" -d "$PAYLOAD")" fi REL_ID="$(jq -r '.id' /tmp/pack-rel.json)" curl -s -o /dev/null -X POST "${GITEA_API}/repos/${GITEA_REPO}/releases/${REL_ID}/assets?name=${PACK_VERSION}.tar.gz" \ -H "Authorization: token ${T}" -H "Content-Type: application/gzip" --data-binary @"${PACK_FILE}" echo "Release ${PACK_VERSION} created with pack asset"