forked from anthropics/claude-code-base-action
-
Notifications
You must be signed in to change notification settings - Fork 49
104 lines (88 loc) · 3.42 KB
/
Copy pathupdate-downstream-action.yml
File metadata and controls
104 lines (88 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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@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="${{ inputs.tag }}"
# Checkout the specific tag
git fetch --tags
git checkout "refs/tags/${TAG_NAME}"
elif [ "${{ github.event_name }}" = "repository_dispatch" ]; then
TAG_NAME="${{ github.event.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
- 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 }}"