|
@@ -1,34 +1,46 @@
|
|
|
-name: Build Xray
|
|
|
+name: Build Xray-core
|
|
|
|
|
|
on:
|
|
|
- # schedule:
|
|
|
- # - cron: "0 20 */7 * *"
|
|
|
workflow_dispatch:
|
|
|
+ inputs:
|
|
|
+ build_type:
|
|
|
+ description: "选择构建类型"
|
|
|
+ required: true
|
|
|
+ default: "stable"
|
|
|
+ type: choice
|
|
|
+ options:
|
|
|
+ - stable
|
|
|
+ - pre-release
|
|
|
+ release:
|
|
|
+ types: [published]
|
|
|
+ repositories: [XTLS/Xray-core]
|
|
|
|
|
|
jobs:
|
|
|
build-xray:
|
|
|
runs-on: ubuntu-latest
|
|
|
steps:
|
|
|
- - name: Set Variables
|
|
|
- run: |
|
|
|
- echo "XRAY_PRE_VERSION=$(curl -fsSL https://api.github.com/repos/xtls/xray-core/tags | grep '"name":' | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/v//g;s/,//g;s/ //g')" >> $GITHUB_ENV
|
|
|
- echo "XRAY_VERSION=$(curl -fsSL https://api.github.com/repos/xtls/xray-core/releases/latest | grep '"tag_name":' | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/v//g;s/,//g;s/ //g')" >> $GITHUB_ENV
|
|
|
- shell: bash
|
|
|
-
|
|
|
- name: Check Out Repo
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
|
- - name: Set up Docker Buildx
|
|
|
- uses: docker/setup-buildx-action@v3
|
|
|
- id: buildx
|
|
|
+ # 自动触发时获取 release 版本号
|
|
|
+ - name: Get Release Version (Auto Trigger)
|
|
|
+ if: github.event_name == 'release'
|
|
|
+ run: |
|
|
|
+ echo "XRAY_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
|
|
|
+ echo "BUILD_TYPE=stable" >> $GITHUB_ENV
|
|
|
|
|
|
- - name: Cache Docker layers
|
|
|
- uses: actions/cache@v4
|
|
|
- with:
|
|
|
- path: /tmp/.buildx-cache
|
|
|
- key: ${{ runner.os }}-buildx-${{ github.sha }}
|
|
|
- restore-keys: |
|
|
|
- ${{ runner.os }}-buildx-
|
|
|
+ # 手动触发时获取最新版本号
|
|
|
+ - name: Get Latest Version (Manual Trigger)
|
|
|
+ if: github.event_name == 'workflow_dispatch'
|
|
|
+ run: |
|
|
|
+ if [ "${{ inputs.build_type }}" == "stable" ]; then
|
|
|
+ VERSION=$(curl -fsSL https://api.github.com/repos/XTLS/Xray-core/releases/latest | grep '"tag_name":' | head -n 1 | awk -F '"' '{print $4}' | sed 's/v//')
|
|
|
+ echo "BUILD_TYPE=stable" >> $GITHUB_ENV
|
|
|
+ else
|
|
|
+ VERSION=$(curl -fsSL https://api.github.com/repos/XTLS/Xray-core/tags | grep '"name":' | head -n 1 | awk -F '"' '{print $4}' | sed 's/v//')
|
|
|
+ echo "BUILD_TYPE=pre-release" >> $GITHUB_ENV
|
|
|
+ fi
|
|
|
+ echo "XRAY_VERSION=$VERSION" >> $GITHUB_ENV
|
|
|
|
|
|
- name: Login to Docker Hub
|
|
|
uses: docker/login-action@v3
|
|
@@ -36,49 +48,33 @@ jobs:
|
|
|
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
|
|
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
|
|
|
|
|
|
- - name: Login to GitHub Container Registry
|
|
|
+ - name: Login to GHCR
|
|
|
uses: docker/login-action@v3
|
|
|
with:
|
|
|
registry: ghcr.io
|
|
|
username: ${{ github.actor }}
|
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
|
|
- - name: Build and push Docker images
|
|
|
- uses: docker/build-push-action@v5
|
|
|
- id: docker_build_xray_core_pre
|
|
|
- with:
|
|
|
- context: ./xray
|
|
|
- file: ./xray/Dockerfile
|
|
|
- push: true
|
|
|
- tags: |
|
|
|
- ${{ secrets.DOCKER_HUB_USERNAME }}/xray:${{ env.XRAY_PRE_VERSION }}
|
|
|
- ghcr.io/${{ github.repository }}/xray:${{ env.XRAY_PRE_VERSION }}
|
|
|
- builder: ${{ steps.buildx.outputs.name }}
|
|
|
- cache-from: type=local,src=/tmp/.buildx-cache
|
|
|
- cache-to: type=local,dest=/tmp/.buildx-cache-new
|
|
|
+ # 稳定版构建
|
|
|
+ - name: Build Stable Image
|
|
|
+ if: env.BUILD_TYPE == 'stable'
|
|
|
+ run: |
|
|
|
+ docker build -f ./xray/Dockerfile.latest -t ${{ secrets.DOCKER_HUB_USERNAME }}/xray:latest ./xray
|
|
|
+ docker tag ${{ secrets.DOCKER_HUB_USERNAME }}/xray:latest ${{ secrets.DOCKER_HUB_USERNAME }}/xray:${{ env.XRAY_VERSION }}
|
|
|
+ docker push ${{ secrets.DOCKER_HUB_USERNAME }}/xray:latest
|
|
|
+ docker push ${{ secrets.DOCKER_HUB_USERNAME }}/xray:${{ env.XRAY_VERSION }}
|
|
|
|
|
|
- - name: Build and push Docker images
|
|
|
- uses: docker/build-push-action@v5
|
|
|
- id: docker_build_xray_core
|
|
|
- with:
|
|
|
- context: ./xray
|
|
|
- file: ./xray/Dockerfile.latest
|
|
|
- push: true
|
|
|
- tags: |
|
|
|
- ${{ secrets.DOCKER_HUB_USERNAME }}/xray:latest
|
|
|
- ${{ secrets.DOCKER_HUB_USERNAME }}/xray:${{ env.XRAY_VERSION }}
|
|
|
- ghcr.io/${{ github.repository }}/xray:latest
|
|
|
- ghcr.io/${{ github.repository }}/xray:${{ env.XRAY_VERSION }}
|
|
|
- builder: ${{ steps.buildx.outputs.name }}
|
|
|
- cache-from: type=local,src=/tmp/.buildx-cache
|
|
|
- cache-to: type=local,dest=/tmp/.buildx-cache-new
|
|
|
+ docker tag ${{ secrets.DOCKER_HUB_USERNAME }}/xray:latest ghcr.io/${{ github.repository }}/xray:latest
|
|
|
+ docker tag ${{ secrets.DOCKER_HUB_USERNAME }}/xray:latest ghcr.io/${{ github.repository }}/xray:${{ env.XRAY_VERSION }}
|
|
|
+ docker push ghcr.io/${{ github.repository }}/xray:latest
|
|
|
+ docker push ghcr.io/${{ github.repository }}/xray:${{ env.XRAY_VERSION }}
|
|
|
|
|
|
- - name: Move cache
|
|
|
+ # Pre-release 构建
|
|
|
+ - name: Build Pre-release Image
|
|
|
+ if: env.BUILD_TYPE == 'pre-release'
|
|
|
run: |
|
|
|
- rm -rf /tmp/.buildx-cache
|
|
|
- mv /tmp/.buildx-cache-new /tmp/.buildx-cache
|
|
|
+ docker build -f ./xray/Dockerfile -t ${{ secrets.DOCKER_HUB_USERNAME }}/xray:${{ env.XRAY_VERSION }} ./xray
|
|
|
+ docker push ${{ secrets.DOCKER_HUB_USERNAME }}/xray:${{ env.XRAY_VERSION }}
|
|
|
|
|
|
- - name: Image digest
|
|
|
- run: |
|
|
|
- echo ${{ steps.docker_build_xray_core_pre.outputs.digest }}
|
|
|
- echo ${{ steps.docker_build_xray_core.outputs.digest }}
|
|
|
+ docker tag ${{ secrets.DOCKER_HUB_USERNAME }}/xray:${{ env.XRAY_VERSION }} ghcr.io/${{ github.repository }}/xray:${{ env.XRAY_VERSION }}
|
|
|
+ docker push ghcr.io/${{ github.repository }}/xray:${{ env.XRAY_VERSION }}
|