Nightly Build and Publish #81
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Nightly Build and Publish | |
| on: | |
| schedule: | |
| # 每天晚上 17:00 UTC (北京时间 1:00) 运行 | |
| - cron: '0 17 * * *' | |
| workflow_dispatch: # 允许手动触发 | |
| env: | |
| ARCH: x86_64 | |
| RUSTUP_DIST_SERVER: "https://rsproxy.cn" | |
| RUSTUP_UPDATE_ROOT: "https://rsproxy.cn/rustup" | |
| jobs: | |
| build: | |
| name: Build DragonOS | |
| if: github.event_name == 'workflow_dispatch' || github.repository == 'DragonOS-Community/DragonOS' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 120 | |
| env: | |
| HOME: /root | |
| container: | |
| image: dragonos/dragonos-dev:v1.23 | |
| options: --privileged -v /dev:/dev | |
| steps: | |
| - name: Checkout DragonOS code | |
| uses: actions/checkout@v4 | |
| - name: Change source | |
| run: | | |
| find . -type f \( -name "*.toml" -o -name "Makefile" \) -exec sed -i 's/git\.mirrors\.dragonos\.org\.cn/github\.com/g' {} + | |
| - name: Build DragonOS | |
| shell: bash -ileo pipefail {0} | |
| run: | | |
| make clean | |
| SKIP_GRUB=1 make build | |
| - name: Verify build artifacts | |
| shell: bash -ileo pipefail {0} | |
| run: | | |
| if [ ! -f "bin/kernel/kernel.elf" ]; then | |
| echo "错误: bin/kernel/kernel.elf 不存在" | |
| exit 1 | |
| fi | |
| if [ ! -f "bin/disk-image-x86_64.img" ]; then | |
| echo "错误: bin/disk-image-x86_64.img 不存在" | |
| exit 1 | |
| fi | |
| echo "构建产物验证成功" | |
| ls -lh bin/kernel/kernel.elf bin/disk-image-x86_64.img | |
| - name: Compress build artifacts | |
| shell: bash -ileo pipefail {0} | |
| run: | | |
| cd bin | |
| tar -czf dragonos-artifacts.tar.gz kernel/kernel.elf disk-image-x86_64.img | |
| ls -lh dragonos-artifacts.tar.gz | |
| echo "压缩完成,压缩包大小:" | |
| du -h dragonos-artifacts.tar.gz | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: build-artifacts | |
| path: bin/dragonos-artifacts.tar.gz | |
| retention-days: 1 | |
| publish: | |
| name: Publish Docker Image | |
| if: github.event_name == 'workflow_dispatch' || github.repository == 'DragonOS-Community/DragonOS' | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - name: Checkout DragonOS code | |
| uses: actions/checkout@v4 | |
| - name: Prepare directory | |
| run: | | |
| mkdir -p bin | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: build-artifacts | |
| path: bin/ | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Generate image tag | |
| id: image-tag | |
| run: | | |
| DATE_TAG=$(date +%Y%m%d) | |
| REGISTRY_URL=docker.cnb.cool | |
| IMAGE_NAME=dragonos-community/playground/artifacts | |
| FULL_IMAGE_NAME="${REGISTRY_URL}/${IMAGE_NAME}" | |
| echo "tag=${FULL_IMAGE_NAME}:nightly-latest" >> "$GITHUB_OUTPUT" | |
| echo "Full image name: ${FULL_IMAGE_NAME}" | |
| - name: Login to container registry | |
| uses: docker/login-action@v2 | |
| with: | |
| registry: docker.cnb.cool | |
| username: cnb | |
| password: ${{ secrets.CNB_PLAYGROUND_REGISTRY_PASSWORD }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: . | |
| file: tools/Dockerfile.artifacts | |
| platforms: linux/amd64 | |
| push: true | |
| tags: | | |
| ${{ steps.image-tag.outputs.tag }} | |