Files
tg-ws-proxy-go/.github/workflows/build.yml
spatiumstas 83d27dcc97 Release 0.9
2026-06-25 10:40:51 +03:00

245 lines
8.0 KiB
YAML

name: Build tg-ws-proxy
on:
workflow_dispatch:
release:
types: [created]
permissions:
contents: write
jobs:
prepare:
name: Prepare build matrix
runs-on: ubuntu-latest
outputs:
configs: ${{ steps.collect.outputs.configs }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Build config matrix
id: collect
run: |
python3 - <<'PY' >> "$GITHUB_OUTPUT"
import json
from pathlib import Path
configs = sorted(Path("config").glob("*/*.config"))
if not configs:
raise SystemExit("No build configs found")
matrix = []
for config in configs:
matrix.append({
"config": config.as_posix(),
"name": config.stem,
})
print(f"configs={json.dumps(matrix, separators=(',', ':'))}")
PY
test:
name: Unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: src/go.mod
cache: true
cache-dependency-path: src/go.sum
- name: Run tests
run: cd src && go test ./...
build:
name: Build packages (${{ matrix.name }})
needs: [ prepare, test ]
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.prepare.outputs.configs) }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version-file: src/go.mod
cache: true
cache-dependency-path: src/go.sum
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y dos2unix
wget https://github.com/upx/upx/releases/download/v5.1.1/upx-5.1.1-amd64_linux.tar.xz
tar -xf upx-5.1.1-amd64_linux.tar.xz
sudo mv upx-5.1.1-amd64_linux/upx /usr/local/bin/upx
sudo chmod +x /usr/local/bin/upx
- name: Install apk-tools
if: ${{ startsWith(matrix.config, 'config/openwrt/') }}
run: |
docker run --rm -v /usr/local/bin:/mnt alpine:edge sh -c "apk add --no-cache apk-tools-static && cp /sbin/apk.static /mnt/apk && chmod +x /mnt/apk"
- name: Build and package
env:
OPENWRT_APK_SECRET_KEY: ${{ secrets.OPENWRT_APK_SECRET_KEY }}
run: |
cp "${{ matrix.config }}" .config
if [[ "${{ matrix.config }}" == config/openwrt/* ]]; then
if [ -z "$OPENWRT_APK_SECRET_KEY" ]; then
echo "OpenWrt APK signing key is required: OPENWRT_APK_SECRET_KEY" >&2
exit 1
fi
KEY_FILE="$RUNNER_TEMP/openwrt-apk-private.pem"
printf '%s' "$OPENWRT_APK_SECRET_KEY" > "$KEY_FILE"
export BUILD_KEY_APK_SEC="$KEY_FILE"
fi
make package
- name: Collect package files
id: package_outputs
run: |
mapfile -t ipk_packages < <(find .build -maxdepth 1 -type f -name 'tg-ws-proxy_*.ipk' | sort)
if [ ${#ipk_packages[@]} -eq 0 ]; then
echo "No ipk package files found" >&2
exit 1
fi
if [ ${#ipk_packages[@]} -gt 1 ]; then
echo "Expected one ipk package file, found ${#ipk_packages[@]}" >&2
printf '%s\n' "${ipk_packages[@]}"
exit 1
fi
package_ipk="${ipk_packages[0]}"
if [[ "${{ matrix.config }}" == config/openwrt/* ]]; then
mapfile -t apk_packages < <(find .build -maxdepth 1 -type f -name 'tg-ws-proxy_*.apk' | sort)
if [ ${#apk_packages[@]} -eq 0 ]; then
echo "No apk package files found for OpenWrt build" >&2
exit 1
fi
if [ ${#apk_packages[@]} -gt 1 ]; then
echo "Expected one apk package file, found ${#apk_packages[@]}" >&2
printf '%s\n' "${apk_packages[@]}"
exit 1
fi
package_apk="${apk_packages[0]}"
fi
echo "package_ipk=$package_ipk" >> "$GITHUB_OUTPUT"
package_ipk_name="$(basename "$package_ipk")"
echo "package_ipk_name=$package_ipk_name" >> "$GITHUB_OUTPUT"
if [ -n "${package_apk:-}" ]; then
echo "package_apk=$package_apk" >> "$GITHUB_OUTPUT"
package_apk_name="$(basename "$package_apk")"
echo "package_apk_name=$package_apk_name" >> "$GITHUB_OUTPUT"
fi
- name: Upload IPK artifact
uses: actions/upload-artifact@v7
with:
name: ${{ steps.package_outputs.outputs.package_ipk_name }}
path: ${{ steps.package_outputs.outputs.package_ipk }}
if-no-files-found: error
compression-level: 0
retention-days: 1
- name: Upload APK artifact
if: ${{ steps.package_outputs.outputs.package_apk != '' }}
uses: actions/upload-artifact@v7
with:
name: ${{ steps.package_outputs.outputs.package_apk_name }}
path: ${{ steps.package_outputs.outputs.package_apk }}
if-no-files-found: error
compression-level: 0
retention-days: 1
publish-latest-release:
runs-on: ubuntu-latest
needs: [ build ]
steps:
- name: Download build artifacts
uses: actions/download-artifact@v8
with:
path: out
merge-multiple: true
- name: Resolve latest target release
id: target-release
uses: actions/github-script@v8
with:
script: |
const { owner, repo } = context.repo;
const releases = await github.paginate(github.rest.repos.listReleases, {
owner,
repo,
per_page: 100,
});
const picked = releases.find((rel) => !rel.draft && !rel.prerelease);
if (!picked) {
core.setFailed('No release found to update');
return;
}
core.setOutput('id', String(picked.id));
core.setOutput('tag', picked.tag_name);
- name: Remove previous package assets
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_ID: ${{ steps.target-release.outputs.id }}
run: |
gh api "repos/${{ github.repository }}/releases/${RELEASE_ID}/assets" \
--jq '.[] | select(.name | test("^tg-ws-proxy.*\\.(ipk|apk|pem)$")) | .id' \
| while read -r asset_id; do
[ -n "$asset_id" ] || continue
gh api -X DELETE "repos/${{ github.repository }}/releases/assets/${asset_id}"
done
- name: Prepare APK public key asset
env:
OPENWRT_APK_PUBLIC_KEY: ${{ secrets.OPENWRT_APK_PUBLIC_KEY }}
run: |
if [ -n "$OPENWRT_APK_PUBLIC_KEY" ]; then
printf '%s' "$OPENWRT_APK_PUBLIC_KEY" > out/tg-ws-proxy.pem
fi
- name: Upload new package assets to latest release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ steps.target-release.outputs.tag }}
run: |
mapfile -t files < <(find out -type f \( -name 'tg-ws-proxy_*.ipk' -o -name 'tg-ws-proxy_*.apk' -o -name '*.pem' \) | sort)
if [ ${#files[@]} -eq 0 ]; then
echo "No package files found"
exit 1
fi
printf '%s\n' "${files[@]}"
gh release upload "$TAG" "${files[@]}" --clobber --repo "${{ github.repository }}"
- name: Dispatch to feedly
if: success()
run: |
curl -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token ${{ secrets.AGGREGATOR_PAT }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/spatiumstas/feedly/dispatches \
-d '{"event_type":"package-built","client_payload":{"package":"'"${{ github.repository }}"'","channel":"release","tag":"'"${{ steps.target-release.outputs.tag }}"'"}}'