diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index aa2e3908..69145582 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -143,3 +143,4 @@ jobs: ${{ github.workspace }}/*.tgz ${{ github.workspace }}/dist/craft ${{ github.workspace }}/gh-pages.zip + if-no-files-found: ignore diff --git a/action.yml b/action.yml index 9e1c4b48..1e1457f2 100644 --- a/action.yml +++ b/action.yml @@ -35,6 +35,12 @@ inputs: description: Use the craft config from the merge target branch required: false default: "false" + craft_version: + description: > + Version of Craft to install (tag or "latest"). + Defaults to the action ref (e.g., "v2") if not specified. + required: false + default: "" outputs: version: @@ -83,16 +89,66 @@ runs: echo "GIT_AUTHOR_NAME=${GIT_USER_NAME}" >> $GITHUB_ENV echo "EMAIL=${GIT_USER_EMAIL}" >> $GITHUB_ENV - # For dogfooding (Craft releasing itself) - local path works because - # the checkout is in the Craft repo, so ./install resolves correctly - - name: Install Craft (local) + # === Install Craft === + # For dogfooding (getsentry/craft): try build artifact from build job + # For all repos (or if artifact unavailable): download from release + + - name: Download Craft from build artifact + id: craft-artifact if: github.repository == 'getsentry/craft' - uses: ./install + uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4 + with: + name: ${{ github.sha }} + path: /tmp/craft-artifact - # For external repos - use fully-qualified reference with action ref - - name: Install Craft - if: github.repository != 'getsentry/craft' - uses: getsentry/craft/install@${{ github.action_ref }} + - name: Install Craft from artifact or release + shell: bash + run: | + set -euo pipefail + + if [[ -f /tmp/craft-artifact/dist/craft ]]; then + echo "Installing Craft from build artifact..." + sudo install -m 755 /tmp/craft-artifact/dist/craft /usr/local/bin/craft + else + # Download from release (for external repos or if artifact unavailable) + # Use explicit craft_version input if provided, otherwise fall back to github.action_ref + CRAFT_VERSION="${{ inputs.craft_version }}" + if [[ -z "$CRAFT_VERSION" ]]; then + CRAFT_VERSION="${{ github.action_ref }}" + fi + + if [[ "$CRAFT_VERSION" == "latest" || -z "$CRAFT_VERSION" ]]; then + echo "Downloading latest Craft release..." + CRAFT_URL=$(curl -fsSL "https://api.github.com/repos/getsentry/craft/releases/latest" \ + | jq -r '.assets[] | select(.name == "craft") | .browser_download_url') + else + CRAFT_URL="https://github.com/getsentry/craft/releases/download/${CRAFT_VERSION}/craft" + echo "Downloading Craft ${CRAFT_VERSION} from: ${CRAFT_URL}" + + # Fallback to latest if specified version doesn't have a release + if ! curl -sfI "$CRAFT_URL" >/dev/null 2>&1; then + echo "Release not found for version '${CRAFT_VERSION}', falling back to latest..." + CRAFT_URL=$(curl -fsSL "https://api.github.com/repos/getsentry/craft/releases/latest" \ + | jq -r '.assets[] | select(.name == "craft") | .browser_download_url') + fi + fi + + # Verify we have a valid URL + if [[ -z "$CRAFT_URL" ]]; then + echo "::error::Failed to determine Craft download URL. The GitHub API may have failed or the release asset is missing." + exit 1 + fi + + echo "Installing Craft from: ${CRAFT_URL}" + sudo curl -fsSL -o /usr/local/bin/craft "$CRAFT_URL" + sudo chmod +x /usr/local/bin/craft + + # Verify the binary was downloaded successfully + if [[ ! -s /usr/local/bin/craft ]]; then + echo "::error::Downloaded Craft binary is empty or missing" + exit 1 + fi + fi - name: Craft Prepare id: craft diff --git a/install/action.yml b/install/action.yml deleted file mode 100644 index 4ecd7f0e..00000000 --- a/install/action.yml +++ /dev/null @@ -1,83 +0,0 @@ -name: "Install Craft" -description: "Install Craft CLI (from build artifact for dogfooding, build from source, or from release)" - -inputs: - craft-version: - description: 'Version of Craft to install (tag or "latest"). Only used when installing from release.' - required: false - default: 'latest' - -runs: - using: "composite" - steps: - - name: Download Craft from build artifact - id: artifact - if: github.repository == 'getsentry/craft' - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4 - continue-on-error: true - with: - name: ${{ github.sha }} - path: /tmp/craft-artifact - - - name: Install Craft from artifact - if: steps.artifact.outcome == 'success' - shell: bash - run: | - echo "Installing Craft from build artifact..." - sudo install -m 755 /tmp/craft-artifact/dist/craft /usr/local/bin/craft - - # For getsentry/craft repo: build from source if no artifact available - - name: Setup Node.js (for building from source) - if: github.repository == 'getsentry/craft' && steps.artifact.outcome != 'success' - uses: actions/setup-node@v4 - with: - node-version: '22' - - - name: Get pnpm version from Volta config - if: github.repository == 'getsentry/craft' && steps.artifact.outcome != 'success' - id: pnpm-version - shell: bash - run: echo "version=$(jq -r '.volta.pnpm' package.json)" >> $GITHUB_OUTPUT - - - name: Setup pnpm - if: github.repository == 'getsentry/craft' && steps.artifact.outcome != 'success' - uses: pnpm/action-setup@v4 - with: - version: ${{ steps.pnpm-version.outputs.version }} - - - name: Build Craft from source - id: build - if: github.repository == 'getsentry/craft' && steps.artifact.outcome != 'success' - shell: bash - run: | - echo "Building Craft from source..." - pnpm install --frozen-lockfile - pnpm build - sudo install -m 755 dist/craft /usr/local/bin/craft - - - name: Install Craft from release - if: steps.artifact.outcome != 'success' && steps.build.outcome != 'success' - shell: bash - env: - CRAFT_VERSION: ${{ inputs.craft-version }} - run: | - if [[ "$CRAFT_VERSION" == "latest" || -z "$CRAFT_VERSION" ]]; then - # Try action ref first (e.g., v2, 2.15.0) - ACTION_REF="${{ github.action_ref }}" - CRAFT_URL="https://github.com/getsentry/craft/releases/download/${ACTION_REF}/craft" - - echo "Trying to download Craft from: ${CRAFT_URL}" - - # Fallback to latest if ref doesn't have a release - if ! curl -sfI "$CRAFT_URL" >/dev/null 2>&1; then - echo "Release not found for ref '${ACTION_REF}', falling back to latest..." - CRAFT_URL=$(curl -s "https://api.github.com/repos/getsentry/craft/releases/latest" \ - | jq -r '.assets[] | select(.name == "craft") | .browser_download_url') - fi - else - CRAFT_URL="https://github.com/getsentry/craft/releases/download/${CRAFT_VERSION}/craft" - fi - - echo "Installing Craft from: ${CRAFT_URL}" - sudo curl -sL -o /usr/local/bin/craft "$CRAFT_URL" - sudo chmod +x /usr/local/bin/craft