Skip to content

Commit 9381d60

Browse files
committed
add signature
1 parent 8771925 commit 9381d60

File tree

1 file changed

+77
-76
lines changed

1 file changed

+77
-76
lines changed

.github/workflows/trademark-cla-approval.yml

Lines changed: 77 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -137,82 +137,10 @@ jobs:
137137
138138
console.log('Added trademark-addendum-signed label successfully');
139139
140-
// IMMEDIATELY record the signature in the same step
141-
console.log('=== Recording signature immediately ===');
142-
143-
// Record signature using GitHub's REST API to create/update the file
144-
const currentDate = new Date().toISOString();
145-
const signaturesFilePath = 'contribute/trade-addendum-signatures.json';
146-
147-
// Get existing signatures file if it exists
148-
let existingContent = { signatures: [] };
149-
try {
150-
const { data: existingFile } = await github.rest.repos.getContent({
151-
owner: context.repo.owner,
152-
repo: context.repo.repo,
153-
path: signaturesFilePath
154-
});
155-
156-
const content = Buffer.from(existingFile.content, 'base64').toString('utf8');
157-
existingContent = JSON.parse(content);
158-
console.log('Found existing signatures file');
159-
} catch (error) {
160-
console.log('No existing signatures file found, creating new one');
161-
existingContent = { signatures: [] };
162-
}
163-
164-
// Check if signature already exists for this user and PR
165-
const existingSignature = existingContent.signatures.find(sig =>
166-
sig.username === prAuthor && sig.pr_number === parseInt(prNumber)
167-
);
168-
169-
if (!existingSignature) {
170-
// Add new signature
171-
const newSignature = {
172-
username: prAuthor,
173-
date: currentDate,
174-
pr_number: parseInt(prNumber),
175-
approved_by: prAuthor
176-
};
177-
178-
existingContent.signatures.push(newSignature);
179-
console.log(`Adding new signature for ${prAuthor}`);
180-
181-
// Create/update the file
182-
const updatedContent = JSON.stringify(existingContent, null, 2);
183-
const contentBase64 = Buffer.from(updatedContent).toString('base64');
184-
185-
try {
186-
// Try to update existing file
187-
const { data: existingFile } = await github.rest.repos.getContent({
188-
owner: context.repo.owner,
189-
repo: context.repo.repo,
190-
path: signaturesFilePath
191-
});
192-
193-
await github.rest.repos.createOrUpdateFileContents({
194-
owner: context.repo.owner,
195-
repo: context.repo.repo,
196-
path: signaturesFilePath,
197-
message: `Add trademark addendum signature for @${prAuthor} (PR #${prNumber})\n\nThis signature was recorded automatically by the CLA approval workflow.`,
198-
content: contentBase64,
199-
sha: existingFile.sha
200-
});
201-
} catch (error) {
202-
// File doesn't exist, create it
203-
await github.rest.repos.createOrUpdateFileContents({
204-
owner: context.repo.owner,
205-
repo: context.repo.repo,
206-
path: signaturesFilePath,
207-
message: `Add trademark addendum signature for @${prAuthor} (PR #${prNumber})\n\nThis signature was recorded automatically by the CLA approval workflow.`,
208-
content: contentBase64
209-
});
210-
}
211-
212-
console.log(`✅ Signature recorded successfully for ${prAuthor}`);
213-
} else {
214-
console.log(`ℹ️ Signature already exists for ${prAuthor} on PR #${prNumber}`);
215-
}
140+
// Store signature details for the next step
141+
core.setOutput('pr_number', prNumber);
142+
core.setOutput('pr_author', prAuthor);
143+
core.setOutput('approved_by', prAuthor);
216144
217145
// Add confirmation comment
218146
const confirmationBody = [
@@ -235,3 +163,76 @@ jobs:
235163
});
236164
237165
console.log(`✅ CLA agreement processed successfully for ${prAuthor}`);
166+
167+
- name: Check out repository
168+
if: success() && steps.process-comment.outputs.pr_number != ''
169+
uses: actions/checkout@v4
170+
with:
171+
fetch-depth: 0
172+
token: ${{ steps.generate-token.outputs.token }}
173+
174+
- name: Record signature to file
175+
if: success() && steps.process-comment.outputs.pr_number != ''
176+
run: |
177+
set -e
178+
179+
echo "=== Recording signature immediately after label addition ==="
180+
181+
# Get signature details
182+
USERNAME="${{ steps.process-comment.outputs.pr_author }}"
183+
DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
184+
PR_NUMBER="${{ steps.process-comment.outputs.pr_number }}"
185+
APPROVED_BY="${{ steps.process-comment.outputs.approved_by }}"
186+
187+
echo "Recording signature for PR #$PR_NUMBER"
188+
echo " Username: $USERNAME"
189+
echo " Approved by: $APPROVED_BY"
190+
echo " Date: $DATE"
191+
192+
# Ensure contribute directory exists
193+
mkdir -p contribute
194+
195+
# Signature file
196+
SIGNATURES_FILE="contribute/trade-addendum-signatures.json"
197+
198+
# Create or read existing signatures file
199+
if [ ! -f "$SIGNATURES_FILE" ]; then
200+
echo '{"signatures": []}' > "$SIGNATURES_FILE"
201+
echo "Created new signatures file"
202+
fi
203+
204+
# Check if signature already exists
205+
EXISTING=$(jq --arg user "$USERNAME" --arg pr "$PR_NUMBER" '.signatures[] | select(.username == $user and .pr_number == ($pr | tonumber))' "$SIGNATURES_FILE" 2>/dev/null || echo "")
206+
207+
if [ -z "$EXISTING" ]; then
208+
# Add new signature
209+
jq --arg user "$USERNAME" \
210+
--arg date "$DATE" \
211+
--arg pr "$PR_NUMBER" \
212+
--arg approved_by "$APPROVED_BY" \
213+
'.signatures += [{
214+
"username": $user,
215+
"date": $date,
216+
"pr_number": ($pr | tonumber),
217+
"approved_by": $approved_by
218+
}]' "$SIGNATURES_FILE" > tmp.json && mv tmp.json "$SIGNATURES_FILE"
219+
220+
echo "✅ Added signature for $USERNAME"
221+
else
222+
echo "ℹ️ Signature already exists for $USERNAME on PR #$PR_NUMBER"
223+
fi
224+
225+
# Configure git
226+
git config user.name "github-actions[bot]"
227+
git config user.email "github-actions[bot]@users.noreply.github.com"
228+
229+
# Check if there are changes and commit
230+
if ! git diff --quiet "$SIGNATURES_FILE"; then
231+
git add "$SIGNATURES_FILE"
232+
git commit -m "Add trademark addendum signature for @$USERNAME (PR #$PR_NUMBER)" \
233+
-m "This signature was recorded automatically by the CLA approval workflow."
234+
git push
235+
echo "✅ Signature committed and pushed successfully"
236+
else
237+
echo "ℹ️ No changes to commit"
238+
fi

0 commit comments

Comments
 (0)