Skip to content

update-downstream-action #29

update-downstream-action

update-downstream-action #29

name: Update Downstream Action
# This workflow updates the anthropics/claude-code-action repository
# when a new release tag is created in this repository
on:
push:
tags:
- "v*.*.*" # Trigger on version tags like v1.2.3
workflow_dispatch:
inputs:
tag:
description: "Tag to update downstream action to (e.g., v1.2.3)"
required: true
type: string
repository_dispatch:
types: [update-downstream-action]
jobs:
update-downstream:
name: Update claude-code-action SHA
runs-on: ubuntu-latest
environment: release
timeout-minutes: 10
steps:
- name: Checkout current repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 0
- name: Get release information
id: release_info
run: |
# Get the tag name based on trigger type
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG_NAME="${INPUT_TAG}"
# Checkout the specific tag
git fetch --tags
git checkout "refs/tags/${TAG_NAME}"
elif [ "${{ github.event_name }}" = "repository_dispatch" ]; then
TAG_NAME="${CLIENT_PAYLOAD_TAG}"
# Checkout the specific tag
git fetch --tags
git checkout "refs/tags/${TAG_NAME}"
else
TAG_NAME=${GITHUB_REF#refs/tags/}
fi
TAG_SHA=$(git rev-parse HEAD)
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
echo "TAG_SHA=$TAG_SHA" >> $GITHUB_ENV
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
echo "tag_sha=$TAG_SHA" >> $GITHUB_OUTPUT
env:
INPUT_TAG: ${{ inputs.tag }}
CLIENT_PAYLOAD_TAG: ${{ github.event.client_payload.tag }}
- name: Clone claude-code-action repository
run: |
# Configure git with the deploy key
mkdir -p ~/.ssh
echo "${{ secrets.CLAUDE_CODE_ACTION_REPO_DEPLOY_KEY }}" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
# Configure SSH to use the deploy key
cat > ~/.ssh/config <<EOL
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/deploy_key
StrictHostKeyChecking no
EOL
# Clone the target repository
git clone git@github.com:anthropics/claude-code-action.git target
- name: Update and push action.yml
run: |
cd target
# Configure git
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
# Read the current action.yml content
ACTION_CONTENT=$(cat action.yml)
# Update the SHA and comment in the action.yml
# This assumes the action.yml has a line like:
# uses: anthropics/claude-code-base-action@SHA # comment
UPDATED_CONTENT=$(echo "$ACTION_CONTENT" | sed -E "s|(uses: anthropics/claude-code-base-action@)[a-f0-9]{40}( *# *.*)?|\1${{ env.TAG_SHA }} # ${{ env.TAG_NAME }}|g")
# Write the updated content
echo "$UPDATED_CONTENT" > action.yml
# Check if there are changes
if git diff --quiet; then
echo "No changes to action.yml, skipping push"
exit 0
fi
# Commit and push if there are changes
git add action.yml
git commit -m "chore: update claude-code-base-action to ${{ env.TAG_NAME }}"
git push origin main
echo "Successfully updated action.yml with claude-code-base-action ${{ env.TAG_NAME }}"