tadoku auth changes #33
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: Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: "Release tag (e.g. 0.1.0 or v0.1.0)" | |
| required: true | |
| type: string | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: write | |
| packages: write | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| prepare: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| should_release: ${{ steps.finalize.outputs.should_release }} | |
| tag: ${{ steps.version.outputs.tag }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Resolve release tag | |
| id: version | |
| shell: bash | |
| env: | |
| EVENT_NAME: ${{ github.event_name }} | |
| INPUT_TAG: ${{ github.event.inputs.tag || '' }} | |
| run: | | |
| if [ "$EVENT_NAME" = "workflow_dispatch" ]; then | |
| if [ -z "$INPUT_TAG" ]; then | |
| echo "inputs.tag is required for manual runs" >&2 | |
| exit 1 | |
| fi | |
| tag="$INPUT_TAG" | |
| version="${tag#v}" | |
| alt_tag="" | |
| else | |
| version="$(python -c 'import tomllib; print(tomllib.load(open("Cargo.toml", "rb"))["package"]["version"])')" | |
| tag="$version" | |
| alt_tag="v$version" | |
| fi | |
| echo "tag=$tag" >> "$GITHUB_OUTPUT" | |
| echo "version=$version" >> "$GITHUB_OUTPUT" | |
| echo "alt_tag=$alt_tag" >> "$GITHUB_OUTPUT" | |
| - name: Check for existing GitHub release | |
| id: release_check | |
| if: github.event_name == 'push' | |
| uses: actions/github-script@v9 | |
| env: | |
| RELEASE_TAG: ${{ steps.version.outputs.tag }} | |
| ALT_RELEASE_TAG: ${{ steps.version.outputs.alt_tag }} | |
| with: | |
| result-encoding: string | |
| script: | | |
| const tags = [process.env.RELEASE_TAG, process.env.ALT_RELEASE_TAG].filter(Boolean); | |
| for (const tag of tags) { | |
| try { | |
| await github.rest.repos.getReleaseByTag({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag, | |
| }); | |
| core.info(`Release already exists for ${tag}`); | |
| return 'true'; | |
| } catch (error) { | |
| if (error.status !== 404) { | |
| throw error; | |
| } | |
| } | |
| } | |
| return 'false'; | |
| - name: Decide whether to publish | |
| id: finalize | |
| shell: bash | |
| env: | |
| EVENT_NAME: ${{ github.event_name }} | |
| RELEASE_EXISTS: ${{ steps.release_check.outputs.result }} | |
| run: | | |
| if [ "$EVENT_NAME" = "workflow_dispatch" ]; then | |
| echo "should_release=true" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| if [ "$RELEASE_EXISTS" = "true" ]; then | |
| echo "Release already exists for ${{ steps.version.outputs.tag }}; skipping." | |
| echo "should_release=false" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "No matching release found; continuing with release." | |
| echo "should_release=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| build: | |
| needs: prepare | |
| if: needs.prepare.outputs.should_release == 'true' | |
| strategy: | |
| matrix: | |
| include: | |
| - target: x86_64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| artifact: nagare-linux-amd64 | |
| binary: nagare | |
| - target: aarch64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| artifact: nagare-linux-arm64 | |
| binary: nagare | |
| - target: x86_64-pc-windows-msvc | |
| os: windows-latest | |
| artifact: nagare-windows-amd64 | |
| binary: nagare.exe | |
| - target: x86_64-apple-darwin | |
| os: macos-latest | |
| artifact: nagare-macos-amd64 | |
| binary: nagare | |
| - target: aarch64-apple-darwin | |
| os: macos-latest | |
| artifact: nagare-macos-arm64 | |
| binary: nagare | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| - name: Build frontend | |
| working-directory: frontend | |
| run: | | |
| npm ci | |
| npm run build | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install cross-compilation tools (Linux ARM64) | |
| if: matrix.target == 'aarch64-unknown-linux-gnu' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu | |
| echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV | |
| echo "CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc" >> $GITHUB_ENV | |
| echo "CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++" >> $GITHUB_ENV | |
| - name: Build release binary | |
| run: cargo build --release --target ${{ matrix.target }} | |
| - name: Package artifact (Unix) | |
| if: runner.os != 'Windows' | |
| run: | | |
| mkdir -p staging | |
| cp target/${{ matrix.target }}/release/${{ matrix.binary }} staging/ | |
| cd staging | |
| tar czf ../${{ matrix.artifact }}.tar.gz ${{ matrix.binary }} | |
| - name: Package artifact (Windows) | |
| if: runner.os == 'Windows' | |
| shell: pwsh | |
| run: | | |
| New-Item -ItemType Directory -Force -Path staging | |
| Copy-Item "target/${{ matrix.target }}/release/${{ matrix.binary }}" staging/ | |
| Compress-Archive -Path "staging/${{ matrix.binary }}" -DestinationPath "${{ matrix.artifact }}.zip" | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.artifact }} | |
| path: | | |
| ${{ matrix.artifact }}.tar.gz | |
| ${{ matrix.artifact }}.zip | |
| docker: | |
| needs: prepare | |
| if: needs.prepare.outputs.should_release == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ghcr.io/${{ github.repository }} | |
| tags: | | |
| type=raw,value=${{ needs.prepare.outputs.tag }} | |
| type=raw,value=latest | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| release: | |
| needs: [prepare, build, docker] | |
| if: needs.prepare.outputs.should_release == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| pattern: "!*.dockerbuild" | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ needs.prepare.outputs.tag }} | |
| target_commitish: ${{ github.sha }} | |
| name: Nagare ${{ needs.prepare.outputs.tag }} | |
| generate_release_notes: true | |
| files: | | |
| artifacts/**/*.tar.gz | |
| artifacts/**/*.zip |