新增 CI 和 Release 流水线,优化构建与发布流程,添加 VERSION 文件以统一版本管理
CI / validate (push) Successful in 5s
CI / build (amd64) (push) Successful in 22s
CI / build (arm64) (push) Successful in 3m48s
Release / build (amd64) (push) Successful in 28s
Release / build (arm64) (push) Successful in 3m30s
Release / release (push) Successful in 35s
CI / validate (push) Successful in 5s
CI / build (amd64) (push) Successful in 22s
CI / build (arm64) (push) Successful in 3m48s
Release / build (amd64) (push) Successful in 28s
Release / build (arm64) (push) Successful in 3m30s
Release / release (push) Successful in 35s
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags: ["*"]
|
||||
|
||||
env:
|
||||
DOCKER_BUILDKIT: "1"
|
||||
BUILDX_NO_DEFAULT_ATTESTATIONS: "1"
|
||||
BUILDKIT_PROGRESS: plain
|
||||
PRODUCT_NAME: xxxig
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{ matrix.arch == 'amd64' && 'ubuntu-latest-amd64' || 'ubuntu-latest-arm64' }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
arch: [amd64, arm64]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: 校验 tag 与源码版本
|
||||
env:
|
||||
TAG: ${{ gitea.ref_name }}
|
||||
run: |
|
||||
VERSION=$(tr -d '\r\n' < VERSION)
|
||||
TAG_VERSION="${TAG#v}"
|
||||
[[ "${TAG_VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]
|
||||
[ "${TAG_VERSION}" = "${VERSION}" ] || {
|
||||
echo "tag ${TAG_VERSION} 与 VERSION ${VERSION} 不一致"
|
||||
exit 1
|
||||
}
|
||||
echo "VERSION=${VERSION}" >> "$GITHUB_ENV"
|
||||
|
||||
- name: 准备原生 Buildx
|
||||
run: |
|
||||
BUILDER=$(docker buildx create --use \
|
||||
--driver docker-container \
|
||||
--driver-opt network=host)
|
||||
echo "BUILDER=${BUILDER}" >> "$GITHUB_ENV"
|
||||
docker buildx inspect --bootstrap
|
||||
|
||||
- name: 构建 ${{ matrix.arch }} 二进制
|
||||
run: |
|
||||
docker buildx build --pull \
|
||||
--platform "linux/${{ matrix.arch }}" \
|
||||
--build-arg "XXXIG_VERSION=v${VERSION}" \
|
||||
--output type=local,dest=./output \
|
||||
-f docker/Dockerfile .
|
||||
|
||||
- name: 打包并冒烟测试
|
||||
run: |
|
||||
DIR="./output/linux_${{ matrix.arch }}"
|
||||
TARGZ="${PRODUCT_NAME}-${{ matrix.arch }}-linux-static-${VERSION}.tar.gz"
|
||||
test -x "${DIR}/xxxigDaemon"
|
||||
test -x "${DIR}/xxxig"
|
||||
test -x "${DIR}/xxxigServer"
|
||||
tar -czf "${TARGZ}" -C "${DIR}" .
|
||||
TEST_DIR=$(mktemp -d)
|
||||
trap 'rm -rf "${TEST_DIR}"' EXIT
|
||||
tar -xzf "${TARGZ}" -C "${TEST_DIR}"
|
||||
"${TEST_DIR}/xxxigDaemon" --version
|
||||
|
||||
- name: 构建 Debian 包
|
||||
run: |
|
||||
if ! command -v dpkg-deb >/dev/null; then
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y dpkg-dev
|
||||
fi
|
||||
TARGZ="${PRODUCT_NAME}-${{ matrix.arch }}-linux-static-${VERSION}.tar.gz"
|
||||
./debian/build-deb.sh "${{ matrix.arch }}" "${VERSION}" "${TARGZ}"
|
||||
DEB="${PRODUCT_NAME}_${VERSION}_${{ matrix.arch }}.deb"
|
||||
CONTENTS=$(dpkg-deb --contents "${DEB}")
|
||||
grep -Fq 'usr/libexec/xxxig-enable-1gb-pages' <<<"${CONTENTS}"
|
||||
grep -Fq 'lib/systemd/system/xxxig-hugepages.service' <<<"${CONTENTS}"
|
||||
|
||||
- uses: https://github.com/ChristopherHX/gitea-upload-artifact@v4
|
||||
with:
|
||||
name: packages-${{ matrix.arch }}
|
||||
path: |
|
||||
*.tar.gz
|
||||
*.deb
|
||||
if-no-files-found: error
|
||||
retention-days: 1
|
||||
|
||||
- name: 清理 Buildx
|
||||
if: always()
|
||||
run: docker buildx rm "${BUILDER}" || true
|
||||
|
||||
release:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest-amd64
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: https://github.com/ChristopherHX/gitea-download-artifact@v4
|
||||
with:
|
||||
pattern: packages-*
|
||||
path: ./packages
|
||||
merge-multiple: true
|
||||
|
||||
- name: 校验发布文件并生成校验和
|
||||
env:
|
||||
TAG: ${{ gitea.ref_name }}
|
||||
run: |
|
||||
VERSION=$(tr -d '\r\n' < VERSION)
|
||||
TAG_VERSION="${TAG#v}"
|
||||
[ "${TAG_VERSION}" = "${VERSION}" ]
|
||||
for arch in amd64 arm64; do
|
||||
test -f "packages/${PRODUCT_NAME}-${arch}-linux-static-${VERSION}.tar.gz"
|
||||
test -f "packages/${PRODUCT_NAME}_${VERSION}_${arch}.deb"
|
||||
done
|
||||
(cd packages && sha256sum *.tar.gz *.deb > SHA256SUMS)
|
||||
REGISTRY=$(echo "${{ gitea.server_url }}" | sed 's|https\?://||')
|
||||
echo "VERSION=${VERSION}" >> "$GITHUB_ENV"
|
||||
echo "REGISTRY=${REGISTRY}" >> "$GITHUB_ENV"
|
||||
|
||||
- name: 上传 Generic 和 Debian 软件包
|
||||
env:
|
||||
TOKEN: ${{ secrets.BUILD_TOKEN }}
|
||||
run: |
|
||||
OWNER="${{ gitea.repository_owner }}"
|
||||
for file in packages/*.tar.gz; do
|
||||
name=$(basename "${file}")
|
||||
curl -fsSL -X PUT \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
--upload-file "${file}" \
|
||||
"https://${REGISTRY}/api/packages/${OWNER}/generic/${PRODUCT_NAME}/${VERSION}/${name}"
|
||||
done
|
||||
for file in packages/*.deb; do
|
||||
curl -fsSL -X PUT \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
--upload-file "${file}" \
|
||||
"https://${REGISTRY}/api/packages/${OWNER}/debian/pool/stable/main/upload"
|
||||
done
|
||||
|
||||
- name: 生成 Release 描述
|
||||
run: |
|
||||
cat > release-notes.md <<EOF
|
||||
## Release ${VERSION}
|
||||
|
||||
### Debian/Ubuntu 安装
|
||||
|
||||
\`\`\`bash
|
||||
sudo curl https://${REGISTRY}/api/packages/${{ gitea.repository_owner }}/debian/repository.key -o /etc/apt/keyrings/gitea-${{ gitea.repository_owner }}.asc
|
||||
echo "deb [signed-by=/etc/apt/keyrings/gitea-${{ gitea.repository_owner }}.asc] https://${REGISTRY}/api/packages/${{ gitea.repository_owner }}/debian stable main" | sudo tee /etc/apt/sources.list.d/${{ gitea.repository_owner }}.list
|
||||
sudo apt-get update && sudo apt-get install xxxig
|
||||
\`\`\`
|
||||
|
||||
发布附件包含 amd64、arm64 的 tar.gz、Debian 包和 SHA256SUMS。
|
||||
EOF
|
||||
|
||||
- name: 创建或更新 Release 并上传附件
|
||||
uses: https://gitea.com/actions/gitea-release-action@v1
|
||||
with:
|
||||
token: ${{ secrets.BUILD_TOKEN }}
|
||||
name: Release ${{ gitea.ref_name }}
|
||||
body_path: release-notes.md
|
||||
files: |
|
||||
packages/*.tar.gz
|
||||
packages/*.deb
|
||||
packages/SHA256SUMS
|
||||
Reference in New Issue
Block a user