name: Add autobump on: workflow_dispatch: inputs: description: description: Description for the package rule required: true type: string ecosystem: description: Ecosystem required: true type: choice options: - action - golang - bun-npm matchUpdateType: description: Update type to allow required: true type: choice default: major options: - major - minor - patch matchPackageName: description: Package name to allow autobump for required: true type: string matchNewValue: description: New value pattern (e.g. v7.* or v7.0.0) required: true type: string jobs: allow-autobump: name: Allow autobump runs-on: ubuntu-latest steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: token: ${{ secrets.GITEA_TOKEN }} - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 with: bun-version-file: ".bun-version" - run: bun install --frozen-lockfile - name: Add package rule id: rule env: DESCRIPTION: ${{ inputs.description }} ECOSYSTEM: ${{ inputs.ecosystem }} MATCH_UPDATE_TYPE: ${{ inputs.matchUpdateType }} MATCH_PACKAGE_NAME: ${{ inputs.matchPackageName }} MATCH_NEW_VALUE: ${{ inputs.matchNewValue }} run: | set -euo pipefail FILE="${ECOSYSTEM}.json" if [[ ! -f "${FILE}" ]]; then echo "::error::Config file ${FILE} does not exist" exit 1 fi MATCH_MANAGERS="$(jq -nc --arg e "${ECOSYSTEM}" '{ "action": ["github-actions"], "golang": ["gomod"], "helm": ["helm-values"], "k8s": ["kubernetes"], "bun-npm": ["npm", "bun"], "docker-compose": ["docker-compose"] }[$e]')" if [[ "${MATCH_MANAGERS}" == "null" || -z "${MATCH_MANAGERS}" ]]; then echo "::error::Unknown ecosystem: ${ECOSYSTEM}" exit 1 fi if [[ -z "${DESCRIPTION}" ]]; then DESCRIPTION="Automerge ${MATCH_UPDATE_TYPE} updates for ${MATCH_PACKAGE_NAME} to ${MATCH_NEW_VALUE}" fi jq \ --arg desc "${DESCRIPTION}" \ --argjson managers "${MATCH_MANAGERS}" \ --arg updateType "${MATCH_UPDATE_TYPE}" \ --arg packageName "${MATCH_PACKAGE_NAME}" \ --arg newValue "${MATCH_NEW_VALUE}" \ ' .packageRules = ((.packageRules // []) + [{ description: $desc, matchManagers: $managers, matchUpdateTypes: [$updateType], matchPackageNames: [$packageName], matchNewValue: $newValue, automerge: true, platformAutomerge: true, automergeType: "pr", addLabels: ["automerge"] }]) ' "${FILE}" > "${FILE}.tmp" mv "${FILE}.tmp" "${FILE}" SAFE_PKG="$(printf '%s' "${MATCH_PACKAGE_NAME}" | tr '/:' '--' | tr -cd '[:alnum:]._-')" SAFE_VAL="$(printf '%s' "${MATCH_NEW_VALUE}" | tr '/:*' '---' | tr -cd '[:alnum:]._-')" BRANCH="chore/allow-autobump-${ECOSYSTEM}-${SAFE_PKG}-${SAFE_VAL}" TITLE="feat(${ECOSYSTEM}): allow automerge of ${MATCH_PACKAGE_NAME} ${MATCH_NEW_VALUE}" { echo "file=${FILE}" echo "branch=${BRANCH}" echo "title=${TITLE}" echo "description=${DESCRIPTION}" } >> "${GITHUB_OUTPUT}" - run: bun run fmt - name: Create pull request env: GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} FILE: ${{ steps.rule.outputs.file }} BRANCH: ${{ steps.rule.outputs.branch }} TITLE: ${{ steps.rule.outputs.title }} DESCRIPTION: ${{ steps.rule.outputs.description }} SERVER_URL: ${{ github.server_url }} REPOSITORY: ${{ github.repository }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} run: | set -euo pipefail git config user.name "gitea-actions" git config user.email "gitea-actions@noreply.local" git checkout -b "${BRANCH}" git add "${FILE}" git commit -m "${TITLE}" git push -u origin "HEAD:${BRANCH}" BODY="$(printf 'Allow Renovate to automerge updates matching:\n\n- **Ecosystem:** `%s`\n- **Package:** `%s`\n- **Update type:** `%s`\n- **New value:** `%s`\n\n%s\n' \ "${{ inputs.ecosystem }}" \ "${{ inputs.matchPackageName }}" \ "${{ inputs.matchUpdateType }}" \ "${{ inputs.matchNewValue }}" \ "${DESCRIPTION}")" RESPONSE="$(curl -sfS -X POST \ -H "Authorization: token ${GITEA_TOKEN}" \ -H "Content-Type: application/json" \ "${SERVER_URL}/api/v1/repos/${REPOSITORY}/pulls" \ -d "$(jq -n \ --arg title "${TITLE}" \ --arg head "${BRANCH}" \ --arg base "${DEFAULT_BRANCH}" \ --arg body "${BODY}" \ '{title: $title, head: $head, base: $base, body: $body}')")" PR_URL="$(printf '%s' "${RESPONSE}" | jq -r '.html_url')" echo "Created pull request: ${PR_URL}"