Update hip-719.md to Final #340
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Assign HIP Number and Rename File | |
on: | |
pull_request: | |
types: [opened, synchronize] | |
defaults: | |
run: | |
shell: bash | |
permissions: | |
contents: write | |
issues: read | |
pull-requests: write | |
checks: write | |
jobs: | |
assign-hip-number: | |
runs-on: improvement-proposals-linux-medium | |
steps: | |
- name: Harden Runner | |
uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 | |
with: | |
egress-policy: audit | |
- name: Check out the code | |
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 | |
with: | |
fetch-depth: 0 | |
- name: Identify if New HIP | |
id: check-new | |
run: | | |
# Fetch the main branch to have all necessary references | |
git fetch origin main | |
# Get the modified files in the PR against the main branch | |
MODIFIED_FILES=$(git diff --name-only origin/main...$GITHUB_SHA) | |
echo "Modified files in PR: $MODIFIED_FILES" | |
# Directory path to check for HIP files | |
HIP_DIRECTORY='HIP' | |
HIP_FILES=$(echo "$MODIFIED_FILES" | grep "^$HIP_DIRECTORY/.*\.md") | |
echo "Filtered HIP files: $HIP_FILES" | |
echo "::set-output name=hip-files::$HIP_FILES" | |
# Check if any HIP files were modified | |
if [ -z "$HIP_FILES" ]; then | |
echo "No HIP files found in the PR." | |
echo "::set-output name=new-hip::false" | |
exit 0 | |
fi | |
# Check each HIP file to see if it exists in the main branch | |
NEW_HIP=true | |
for file in $HIP_FILES; do | |
if git ls-tree -r origin/main --name-only | grep -q "^$file$"; then | |
echo "This PR modifies an existing HIP: $file" | |
NEW_HIP=false | |
break | |
fi | |
done | |
if [ "$NEW_HIP" = "true" ]; then | |
echo "This PR creates a new HIP." | |
echo "::set-output name=new-hip::true" | |
else | |
echo "::set-output name=new-hip::false" | |
fi | |
- name: Assign HIP Number | |
if: steps.check-new.outputs.new-hip == 'true' | |
run: | | |
# Extract the current PR number | |
PR_NUMBER=${{ github.event.pull_request.number }} | |
HIP_HEADER="hip: $PR_NUMBER" | |
HIP_FILE=$(echo "${{ steps.check-new.outputs.hip-files }}" | head -n 1) | |
echo "Assigning HIP number to file: $HIP_FILE" | |
if [ -n "$HIP_FILE" ]; then | |
sed -i "s/^hip:.*$/$HIP_HEADER/" "$HIP_FILE" | |
else | |
echo "No valid HIP file to assign a number." | |
exit 1 | |
fi | |
- name: Rename HIP File | |
if: steps.check-new.outputs.new-hip == 'true' | |
run: | | |
# Extract PR number | |
PR_NUMBER=${{ github.event.pull_request.number }} | |
HIP_FILE=$(echo "${{ steps.check-new.outputs.hip-files }}" | head -n 1) | |
if [ -n "$HIP_FILE" ]; then | |
NEW_HIP_FILE="HIP/hip-$PR_NUMBER.md" | |
mv "$HIP_FILE" "$NEW_HIP_FILE" | |
else | |
echo "No HIP file found to rename." | |
exit 1 | |
fi | |
- name: Commit Changes | |
if: steps.check-new.outputs.new-hip == 'true' | |
run: | | |
git config --global user.name 'GitHub Action' | |
git config --global user.email 'action@github.com' | |
PR_NUMBER=${{ github.event.pull_request.number }} | |
git add HIP/ | |
git commit -m "Assigning HIP $PR_NUMBER and renaming file to hip-$PR_NUMBER.md" | |
git push origin HEAD:${{ github.head_ref }} |