diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index afa7fb40..32736b03 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,7 +15,9 @@ jobs: - name: Set runner id: set-runner run: | - runners=$(curl -s -H "Accept: application/vnd.github+json" -H "Authorization: token ${{ secrets.REPO_ACCESS_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/actions/runners") + runners=$(curl -s -H "Accept: application/vnd.github+json" \ + -H "Authorization: token ${{ secrets.REPO_ACCESS_TOKEN }}" \ + "https://api.github.com/repos/${{ github.repository }}/actions/runners") available=$(echo "$runners" | jq '.runners[] | select(.status == "online" and .busy == false and .labels[] .name == "self-hosted")') if [ -n "$available" ]; then echo "runner-label=self-hosted" >> "$GITHUB_OUTPUT" @@ -23,22 +25,18 @@ jobs: echo "runner-label=ubuntu-latest" >> "$GITHUB_OUTPUT" fi - goreleaser: + frontend: needs: check-runner runs-on: ${{ needs.check-runner.outputs.runner-label }} steps: - # pull code - - name: Checkout - uses: actions/checkout@v5 + - uses: actions/checkout@v5 with: - fetch-depth: 0 + fetch-depth: 1 - # setup pnpm - uses: pnpm/action-setup@v4 with: version: latest - # install latest node - name: Set up Node.js uses: actions/setup-node@v5 with: @@ -46,44 +44,98 @@ jobs: cache: pnpm cache-dependency-path: frontend/pnpm-lock.yaml - # build sveltekit frontend + - name: Cache frontend build + uses: actions/cache@v4 + with: + path: | + frontend/node_modules + frontend/.svelte-kit + key: ${{ runner.os }}-pnpm-${{ hashFiles('frontend/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm- + - name: Build frontend run: | - pnpm --prefix=./frontend i + pnpm --prefix=./frontend install --frozen-lockfile --prefer-offline PUBLIC_VERSION=${GITHUB_REF##*/} pnpm --prefix=./frontend run build - cp -r ./frontend/build/* ./backend/pb_public/ - git reset --hard + tar -czf frontend-dist.tar.gz -C frontend/build . + + - name: Upload frontend artifact + uses: actions/upload-artifact@v4 + with: + name: frontend-dist + path: frontend-dist.tar.gz + + goreleaser: + needs: + - check-runner + - frontend + runs-on: ${{ needs.check-runner.outputs.runner-label }} + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - name: Download frontend artifact + uses: actions/download-artifact@v4 + with: + name: frontend-dist + + - name: Extract frontend into backend + run: | + mkdir -p backend/pb_public + tar -xzf frontend-dist.tar.gz -C backend/pb_public - # setup go - name: Set up Go uses: actions/setup-go@v6 with: - go-version-file: "./backend/go.mod" - cache-dependency-path: "./backend/go.sum" + go-version-file: backend/go.mod + cache-dependency-path: backend/go.sum + + - name: Cache Go build + uses: actions/cache@v4 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('backend/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- - # build - name: Run GoReleaser uses: goreleaser/goreleaser-action@v6 with: distribution: goreleaser version: "~> v2" - args: release --clean + args: release --clean --snapshot --verbose workdir: backend env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} AUR_KEY: ${{ secrets.AUR_KEY }} + - name: Upload backend artifact + uses: actions/upload-artifact@v4 + with: + name: backend-dist + path: backend/dist + docker: needs: - - goreleaser - check-runner + - frontend + - goreleaser runs-on: ${{ needs.check-runner.outputs.runner-label }} steps: - # pull code - - name: Check Out Repo - uses: actions/checkout@v5 + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - name: Download backend artifact + uses: actions/download-artifact@v4 + with: + name: backend-dist + path: backend/dist - # image tags - name: Docker meta id: meta uses: docker/metadata-action@v5 @@ -97,33 +149,27 @@ jobs: type=semver,pattern={{major}} type=semver,pattern={{major}}.{{minor}} - # qemu - name: Set up QEMU uses: docker/setup-qemu-action@v3 - # docker buildx - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v3 - # ghcr.io login - - name: Log in to the Container registry + - name: Log in to GHCR uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - # ducker hub login - - name: Login to Docker Hub + - name: Log in to Docker Hub uses: docker/login-action@v3 with: username: ${{ vars.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - # build and push - name: Build and push - id: docker_build uses: docker/build-push-action@v6 with: context: . @@ -131,5 +177,7 @@ jobs: builder: ${{ steps.buildx.outputs.name }} push: true tags: ${{ steps.meta.outputs.tags }} + cache-from: type=gha + cache-to: type=gha,mode=max build-args: | - VERSION=${{github.ref_name}} + VERSION=${{ github.ref_name }}