-
Notifications
You must be signed in to change notification settings - Fork 40
Refactor build workflow to build binaries for more platform and docker images #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lgc2333
wants to merge
18
commits into
TeamFlos:main
Choose a base branch
from
lgc2333:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
28bf469
Add GitHub Actions workflow for building binaries and images
lgc2333 1370935
chore
lgc2333 ab59dc4
Merge branch 'main' into upstream
lgc2333 edb228c
Merge pull request #2 from lgc2333/upstream
lgc2333 94034d1
Delete .github/workflows/release.yml
lgc2333 bb49a0f
Update release.yml to simplify comments and targets
lgc2333 e5bef6e
Update CI workflow to use env for RUST_TOOLCHAIN
lgc2333 62373bb
Cleanup OpenSSL installation step
lgc2333 ea93e50
Add release job to build and publish binaries
lgc2333 1789e5d
Bump used action versions
lgc2333 de21fc1
Update cosign-installer version in release workflow
lgc2333 39ca657
Cleanup OpenSSL installation
lgc2333 e6a49ad
Add permissions for release workflow
lgc2333 4fae3fe
Fix artifact packaging
lgc2333 2852512
Restore cache step
lgc2333 2087b17
Fix cache
lgc2333 e0b6016
Update rust-toolchain action to use master branch
lgc2333 7727c3a
Update rust-toolchain action to use master branch
lgc2333 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [build] | ||
| rustflags = ["--cfg", "tokio_unstable"] |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,71 +1,195 @@ | ||
| name: release | ||
| name: Build executables and Docker images | ||
|
|
||
| on: | ||
| push: | ||
| tags: ["v*"] | ||
| workflow_dispatch: | ||
|
|
||
| env: | ||
| BIN_NAME: phira-mp-server | ||
| PROJECT_NAME: phira-mp-server | ||
| IMAGE_NAME: ${{ github.repository_owner }}/phira-mp-server | ||
| CARGO_TERM_COLOR: always | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| target: [x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu] | ||
| include: | ||
| - target: x86_64-unknown-linux-gnu | ||
| runs-on: ubuntu-latest | ||
| - target: aarch64-unknown-linux-gnu | ||
| runs-on: ubuntu-24.04-arm | ||
|
|
||
| # cross is trying to build amd64 image on arm runner! | ||
| # so i'm using x86 runner | ||
| - target: x86_64-unknown-linux-musl | ||
| runs-on: ubuntu-latest | ||
| cross-needed: true | ||
| - target: aarch64-unknown-linux-musl | ||
| runs-on: ubuntu-latest | ||
| cross-needed: true | ||
|
|
||
| # use cross build android binaries is more convenient | ||
| - target: aarch64-linux-android | ||
| runs-on: ubuntu-latest | ||
| cross-needed: true | ||
| - target: x86_64-linux-android | ||
| runs-on: ubuntu-latest | ||
| cross-needed: true | ||
|
|
||
| - target: aarch64-apple-darwin | ||
| runs-on: macos-latest | ||
| - target: x86_64-apple-darwin | ||
| runs-on: macos-15-intel | ||
|
|
||
| - target: x86_64-pc-windows-msvc | ||
| runs-on: windows-latest | ||
| - target: aarch64-pc-windows-msvc | ||
| runs-on: windows-11-arm | ||
|
|
||
| name: Build ${{ matrix.target }} | ||
| runs-on: ${{ matrix.runs-on }} | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Write Cross.toml | ||
| - name: Install cross if needed | ||
| if: matrix.cross-needed == true | ||
| run: | | ||
| cat > Cross.toml <<'EOF' | ||
| [target.x86_64-unknown-linux-gnu] | ||
| pre-build = [ | ||
| "dpkg --add-architecture $CROSS_DEB_ARCH", | ||
| "apt-get update && apt-get install --assume-yes pkg-config libssl-dev:$CROSS_DEB_ARCH" | ||
| ] | ||
| [target.aarch64-unknown-linux-gnu] | ||
| pre-build = [ | ||
| "dpkg --add-architecture $CROSS_DEB_ARCH", | ||
| "apt-get update && apt-get install --assume-yes pkg-config libssl-dev:$CROSS_DEB_ARCH" | ||
| ] | ||
| EOF | ||
| cargo install cross --git https://github.com/cross-rs/cross | ||
|
|
||
| - uses: dtolnay/rust-toolchain@stable | ||
| with: | ||
| targets: ${{ matrix.target }} | ||
| - name: Add rustup target (No cross) | ||
| if: matrix.cross-needed != true | ||
| run: rustup target add ${{ matrix.target }} | ||
|
|
||
| - uses: Swatinem/rust-cache@v2 | ||
| with: | ||
| key: release-${{ matrix.target }} | ||
|
|
||
| - name: Install cross | ||
| run: cargo install cross --version 0.2.5 | ||
| - name: Build binary | ||
| run: > | ||
| ${{ matrix.cross-needed == true && 'cross' || 'cargo' }} | ||
| build --target ${{ matrix.target }} --release --workspace | ||
|
|
||
| - name: Upload artifact | ||
| uses: actions/upload-artifact@v7 | ||
| with: | ||
| name: ${{ env.BIN_NAME }}-${{ matrix.target }} | ||
| path: ./target/${{ matrix.target }}/release/${{ env.BIN_NAME }}${{ runner.os == 'Windows' && '.exe' || '' }} | ||
|
|
||
| image: | ||
| name: Build images | ||
| needs: build | ||
| runs-on: ubuntu-latest | ||
|
|
||
| permissions: | ||
| contents: read | ||
| packages: write | ||
| id-token: write | ||
|
|
||
| steps: | ||
| - name: Set up QEMU | ||
| uses: docker/setup-qemu-action@v4 | ||
|
|
||
| - name: Set up cosign | ||
| uses: sigstore/cosign-installer@v3 | ||
|
|
||
| - name: Build ${{ matrix.target }} | ||
| run: cross build --release --workspace --target ${{ matrix.target }} | ||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v4 | ||
|
|
||
| - name: Package binary | ||
| - name: Log in to GitHub Container Registry | ||
| uses: docker/login-action@v4 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.repository_owner }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Create staging directory for binaries | ||
| run: mkdir -p amd64 arm64 | ||
|
|
||
| - name: Download x86_64-unknown-linux-musl artifact | ||
| uses: actions/download-artifact@v8 | ||
| with: | ||
| name: ${{ env.BIN_NAME }}-x86_64-unknown-linux-musl | ||
| path: amd64 | ||
|
|
||
| - name: Download aarch64-unknown-linux-musl artifact | ||
| uses: actions/download-artifact@v8 | ||
| with: | ||
| name: ${{ env.BIN_NAME }}-aarch64-unknown-linux-musl | ||
| path: arm64 | ||
|
|
||
| - name: Make binaries executable | ||
| run: | | ||
| mkdir -p dist | ||
| cp target/${{ matrix.target }}/release/phira-mp-server dist/phira-mp-server-${{ matrix.target }} | ||
| tar -czf dist/phira-mp-server-${{ matrix.target }}.tar.gz -C dist phira-mp-server-${{ matrix.target }} | ||
| chmod +x amd64/${{ env.BIN_NAME }} | ||
| chmod +x arm64/${{ env.BIN_NAME }} | ||
|
|
||
| - name: Write Dockerfile | ||
| run: | | ||
| cat << EOF > Dockerfile | ||
| FROM alpine:3 | ||
| ARG TARGETARCH | ||
| WORKDIR /app | ||
| COPY \${TARGETARCH}/${{ env.BIN_NAME }} . | ||
| EXPOSE 12346 | ||
| ENTRYPOINT ["./${{ env.BIN_NAME }}"] | ||
| EOF | ||
|
|
||
| - uses: actions/upload-artifact@v4 | ||
| - name: Extract metadata for Docker | ||
| id: meta | ||
| uses: docker/metadata-action@v6 | ||
| with: | ||
| name: binaries-${{ matrix.target }} | ||
| path: dist/phira-mp-server-${{ matrix.target }}.tar.gz | ||
| images: ghcr.io/${{ env.IMAGE_NAME }} | ||
| tags: | | ||
| type=sha,prefix= | ||
| type=ref,event=branch | ||
| type=ref,event=tag | ||
|
|
||
| - name: Build and push Docker image | ||
| id: build-and-push | ||
| uses: docker/build-push-action@v7 | ||
| with: | ||
| context: . | ||
| platforms: linux/amd64,linux/arm64 | ||
| push: true | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| labels: ${{ steps.meta.outputs.labels }} | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max | ||
|
|
||
| - name: Sign the published Docker image | ||
| env: | ||
| TAGS: ${{ steps.meta.outputs.tags }} | ||
| DIGEST: ${{ steps.build-and-push.outputs.digest }} | ||
| run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} | ||
|
|
||
| publish: | ||
| release: | ||
| name: Publish release | ||
| needs: build | ||
| if: startsWith(github.ref, 'refs/tags/v') | ||
| runs-on: ubuntu-latest | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| steps: | ||
| - uses: actions/download-artifact@v4 | ||
| - uses: actions/download-artifact@v8 | ||
| with: | ||
| pattern: binaries-* | ||
| merge-multiple: true | ||
| path: dist | ||
| pattern: '*' | ||
| path: artifacts | ||
|
|
||
| - name: Package binaries | ||
| run: | | ||
| mkdir -p dist | ||
| for d in artifacts/*/; do | ||
| name=$(basename "$d") | ||
| (cd "$d" && zip -r "../../dist/$name.zip" .) | ||
| done | ||
|
|
||
| - name: Publish release | ||
| uses: softprops/action-gh-release@v2 | ||
| with: | ||
| draft: false | ||
| files: dist/*.tar.gz | ||
| files: dist/* |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.