name: publish chocolatey on: workflow_call: inputs: plan: required: true type: string permissions: contents: read jobs: publish: runs-on: ubuntu-latest env: PLAN: ${{ inputs.plan }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} CHOCOLATEY_API_KEY: ${{ secrets.CHOCOLATEY_API_KEY }} steps: - uses: actions/checkout@v6 with: ref: ${{ fromJson(inputs.plan).announcement_tag }} - name: verify Chocolatey publishing secret shell: bash run: | if [ -z "${CHOCOLATEY_API_KEY}" ]; then echo "::error::CHOCOLATEY_API_KEY is required to publish rmcl to Chocolatey." exit 1 fi - name: prepare Chocolatey package id: package shell: bash run: | tag="$(jq --raw-output '.announcement_tag' <<< "$PLAN")" version="$(jq --raw-output '.releases[0].app_version' <<< "$PLAN")" package_dir="target/chocolatey/rmcl" checksum_file="rmcl-x86_64-pc-windows-msvc.msi.sha256" mkdir -p "$package_dir" cp -R pkg/chocolatey/* "$package_dir/" gh release download "$tag" --pattern "$checksum_file" --dir "$package_dir" checksum="$(awk '{print $1}' "$package_dir/$checksum_file")" sed -i "s|__TAG__|$tag|g; s|__CHECKSUM64__|$checksum|g" "$package_dir/tools/chocolateyInstall.ps1" echo "version=$version" >> "$GITHUB_OUTPUT" echo "package_dir=$package_dir" >> "$GITHUB_OUTPUT" - name: pack Chocolatey package uses: crazy-max/ghaction-chocolatey@v4 with: args: pack ${{ steps.package.outputs.package_dir }}/rmcl.nuspec --version ${{ steps.package.outputs.version }} --output-directory target/chocolatey/out - name: push Chocolatey package shell: bash run: | package="target/chocolatey/out/rmcl.${{ steps.package.outputs.version }}.nupkg" version="${{ steps.package.outputs.version }}" public_package_url="https://community.chocolatey.org/packages/rmcl/$version" saw_server_error=false for attempt in 1 2 3; do log_file="$RUNNER_TEMP/chocolatey-push-${attempt}.log" if docker run --rm --workdir /wksp --volume "$PWD:/wksp" ghcr.io/crazy-max/chocolatey push "$package" --source "https://push.chocolatey.org/" --api-key "$CHOCOLATEY_API_KEY" --timeout 2700 2>&1 | tee "$log_file"; then exit 0 fi if grep -q "409 (Conflict)" "$log_file"; then echo "::warning::Chocolatey package version already exists; treating this publish as complete." exit 0 fi if grep -qE "50[0-9] \\(" "$log_file"; then saw_server_error=true fi if grep -q "403 (Forbidden)" "$log_file"; then if [ "$saw_server_error" = "true" ]; then echo "::warning::Chocolatey returned 403 after an earlier server error. The previous push may have been accepted and put into moderation; treating this publish as complete." exit 0 fi page_file="$RUNNER_TEMP/chocolatey-package-$version.html" page_status="$(curl --location --silent --show-error --output "$page_file" --write-out "%{http_code}" "$public_package_url")" if [ "$page_status" = "200" ] && grep -qE "awaiting moderation|remain unlisted until it has been approved|Version History" "$page_file"; then echo "::warning::Chocolatey returned 403, but the public package page for version $version exists and is awaiting moderation; treating this publish as complete." exit 0 fi echo "::error::Chocolatey rejected the push with 403 before any server-side failure. Check CHOCOLATEY_API_KEY ownership/permissions for rmcl." exit 1 fi if [ "$attempt" -eq 3 ]; then break fi sleep $((attempt * 30)) done exit 1