chore: 添加带版本号的docker镜像 #72
Workflow file for this run
This file contains 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: build | |
on: | |
workflow_dispatch: # 手动触发 | |
push: | |
branches: ["master"] | |
# Publish semver tags as releases. | |
tags: ["v*.*.*"] | |
pull_request: | |
branches: ["master"] | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
env: | |
# Use docker.io for Docker Hub if empty | |
REGISTRY: ghcr.io | |
jobs: | |
build: | |
strategy: | |
fail-fast: false | |
matrix: | |
settings: | |
- target: x86_64-apple-darwin | |
host: macos-latest | |
build: | | |
cargo build --release --target x86_64-apple-darwin && \ | |
mkdir build && \ | |
cp target/x86_64-apple-darwin/release/wol build/wol && \ | |
strip -x build/wol | |
- target: aarch64-apple-darwin | |
host: macos-latest | |
build: | | |
cargo build --release --target aarch64-apple-darwin && \ | |
mkdir build && \ | |
cp target/aarch64-apple-darwin/release/wol build/wol && \ | |
strip -x build/wol | |
- target: x86_64-pc-windows-msvc | |
host: windows-latest | |
build: | | |
cargo build --release --target x86_64-pc-windows-msvc | |
md build | |
copy target/x86_64-pc-windows-msvc/release/wol.exe build/wol.exe | |
- target: aarch64-pc-windows-msvc | |
host: windows-latest | |
build: | | |
cargo build --release --target aarch64-pc-windows-msvc | |
md build | |
copy target/aarch64-pc-windows-msvc/release/wol.exe build/wol.exe | |
- target: x86_64-unknown-linux-gnu | |
host: ubuntu-latest | |
build: | | |
cargo install cross --force --git https://github.com/cross-rs/cross && \ | |
cross build --release --target x86_64-unknown-linux-gnu && \ | |
mkdir build && \ | |
cp target/x86_64-unknown-linux-gnu/release/wol build/wol && \ | |
strip -x build/wol | |
- target: x86_64-unknown-linux-musl | |
host: ubuntu-latest | |
build: | | |
cargo install cross --force --git https://github.com/cross-rs/cross && \ | |
cross build --release --target x86_64-unknown-linux-musl && \ | |
mkdir build && \ | |
cp target/x86_64-unknown-linux-musl/release/wol build/wol && \ | |
strip -x build/wol | |
- target: aarch64-unknown-linux-gnu | |
host: ubuntu-latest | |
build: | | |
cargo install cross --force --git https://github.com/cross-rs/cross && \ | |
cross build --release --target aarch64-unknown-linux-gnu && \ | |
mkdir build && \ | |
cp target/aarch64-unknown-linux-gnu/release/wol build/wol | |
- target: aarch64-unknown-linux-musl | |
host: ubuntu-latest | |
build: | | |
cargo install cross --force --git https://github.com/cross-rs/cross && \ | |
cross build --release --target aarch64-unknown-linux-musl && \ | |
mkdir build && \ | |
cp target/aarch64-unknown-linux-musl/release/wol build/wol | |
name: build ${{ matrix.settings.target }} | |
runs-on: ${{ matrix.settings.host }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Cache cargo | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/.cargo/bin/ | |
~/.cargo/registry/index/ | |
~/.cargo/registry/cache/ | |
~/.cargo/git/db/ | |
target/ | |
key: ${{ runner.os }}-${{ matrix.settings.target }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
- name: Install rust toolchain | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
toolchain: stable | |
target: ${{ matrix.settings.target }} | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: latest | |
cache: "yarn" | |
cache-dependency-path: web/yarn.lock | |
- name: Build web | |
run: yarn && yarn build | |
working-directory: web | |
- name: Move web files to www | |
run: mv web/dist/* www | |
- name: Build server | |
run: ${{ matrix.settings.build }} | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: wol-${{ matrix.settings.target }} | |
path: build/ | |
if-no-files-found: error | |
publish: | |
runs-on: ubuntu-latest | |
needs: | |
- build | |
if: startsWith(github.ref, 'refs/tags/') | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Download all artifact | |
uses: actions/download-artifact@v4 | |
with: | |
path: artifacts | |
- name: Display structure of downloaded files | |
run: ls -R | |
working-directory: artifacts | |
- name: Pack as zip file | |
run: ls | xargs -I filename zip -r -m filename.zip filename | |
working-directory: artifacts | |
- name: Display structure of zip files | |
run: ls -R | |
working-directory: artifacts | |
- name: Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
files: artifacts/*.zip | |
docker: | |
runs-on: ubuntu-latest | |
needs: | |
- publish | |
if: startsWith(github.ref, 'refs/tags/') | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Setup docker buildx | |
uses: docker/setup-buildx-action@v3 | |
# https://github.com/docker/login-action | |
- name: Login to ${{ env.REGISTRY }} | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push Docker images | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: ${{ env.REGISTRY }}/nashaofu/wol:latest,${{ env.REGISTRY }}/nashaofu/wol:${{ github.ref_name }} |