build(mise) #8
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: build(mise) | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| default: 'latest' | |
| description: 'Package version' | |
| type: string | |
| required: true | |
| schedule: | |
| - cron: '0 20 * * *' | |
| permissions: | |
| contents: write | |
| packages: write | |
| env: | |
| app_name: 'mise' | |
| app_repo: 'jdx/mise' | |
| jobs: | |
| check: | |
| runs-on: ubuntu-slim | |
| outputs: | |
| app_version: ${{ steps.get-version.outputs.app_version }} | |
| app_build: ${{ steps.check-release.outputs.app_build }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Get Version | |
| id: get-version | |
| run: | | |
| if [ "${{ github.event_name }}" = "schedule" ] || [ "${{ github.event.inputs.version }}" = "latest" ]; then | |
| app_version=$(curl -s "https://api.github.com/repos/${{ env.app_repo }}/releases/latest" | jq -r .tag_name) | |
| else | |
| app_version=${{ github.event.inputs.version }} | |
| fi | |
| if [ -z "${app_version}" ] || [ "${app_version}" == "null" ]; then | |
| echo "Failed to get version" | |
| exit 1 | |
| fi | |
| echo "app_version=${app_version}" >> $GITHUB_ENV | |
| echo "app_version=${app_version}" >> $GITHUB_OUTPUT | |
| echo "" | |
| echo "========== Build Args ==========" | |
| echo "app_version=${app_version}" | |
| - name: Check Release | |
| id: check-release | |
| run: | | |
| gh release view ${app_version} -R ${{ github.repository }} | grep ${app_name}-${app_version}-linux-loong64.tar.gz >/dev/null 2>&1 || echo "app_build=1" >> $GITHUB_OUTPUT | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| build-tarball-linux: | |
| if: needs.check.outputs.app_build == '1' | |
| runs-on: ubuntu-latest | |
| needs: check | |
| env: | |
| app_version: ${{ needs.check.outputs.app_version }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - name: linux-loong64 | |
| target: loongarch64-unknown-linux-gnu | |
| - name: linux-loong64-musl | |
| target: loongarch64-unknown-linux-musl | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| repository: ${{ env.app_repo }} | |
| ref: ${{ env.app_version }} | |
| - name: Install cross | |
| uses: taiki-e/install-action@v2 | |
| with: | |
| tool: cross | |
| - name: cache crates | |
| id: cache-crates | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cargo/registry/cache | |
| key: cargo-registry-${{ hashFiles('**/Cargo.lock') }} | |
| restore-keys: cargo-registry | |
| - name: Prepare | |
| run: | | |
| wget -qO - https://github.com/${{ github.repository }}/raw/refs/heads/main/patch_loong64.patch | patch -p1 | |
| - name: build-tarball ${{matrix.target}} | |
| uses: nick-fields/retry@v3 | |
| with: | |
| max_attempts: 3 | |
| timeout_minutes: 100 | |
| command: scripts/build-tarball.sh ${{matrix.target}} | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: tarball-${{matrix.target}} | |
| path: | | |
| dist/mise-*.tar.xz | |
| dist/mise-*.tar.gz | |
| dist/mise-*.tar.zst | |
| if-no-files-found: error | |
| - uses: taiki-e/install-action@v2 | |
| with: { tool: cargo-cache } | |
| - if: steps.cache-crates.outputs.cache-hit != 'true' | |
| run: cargo cache --autoclean | |
| dockerhub: | |
| if: needs.check.outputs.app_build == '1' | |
| runs-on: ${{ matrix.platform.os }} | |
| needs: check | |
| env: | |
| app_version: ${{ needs.check.outputs.app_version }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| platform: | |
| - os: ubuntu-latest | |
| tag_suffix: loong64 | |
| platform: linux/loong64 | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| repository: ${{ env.app_repo }} | |
| ref: ${{ env.app_version }} | |
| - name: Prepare | |
| run: | | |
| platform="${{ matrix.platform.platform }}" | |
| echo "PLATFORM_PAIR=${platform//\//-}" >> "$GITHUB_ENV" | |
| wget -qO - https://github.com/${{ github.repository }}/raw/refs/heads/main/patch_loong64.patch | patch -p1 | |
| sed -i "s|FROM rust@.* AS|FROM ghcr.io/loong64/rust:trixie AS|g" packaging/mise/Dockerfile | |
| - name: Setup QEMU | |
| uses: docker/setup-qemu-action@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and Push base image | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: . | |
| platforms: ${{ matrix.platform.platform }} | |
| push: true | |
| tags: | | |
| ghcr.io/${{ github.repository_owner }}/${{ env.app_repo }}:${{ env.app_version }} | |
| release: | |
| if: needs.check.outputs.app_build == '1' | |
| runs-on: ubuntu-24.04 | |
| needs: | |
| - check | |
| - build-tarball-linux | |
| env: | |
| app_version: ${{ needs.check.outputs.app_version }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Download release | |
| uses: actions/download-artifact@v8 | |
| with: | |
| pattern: tarball-* | |
| path: dist | |
| merge-multiple: true | |
| - name: Create release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| TAG_NAME="${{ env.app_version }}" | |
| gh release create "${TAG_NAME}" \ | |
| --generate-notes \ | |
| --title "${TAG_NAME}" \ | |
| dist/* |