update #151
Workflow file for this run
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: PR Check and Merge | |
on: | |
pull_request: | |
types: | |
- opened | |
- edited | |
- synchronize | |
permissions: | |
pull-requests: write | |
contents: write | |
jobs: | |
audit: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check if PR is from a fork | |
id: pr_source | |
run: | | |
if [[ "${{ github.event.pull_request.head.repo.full_name }}" != "${{ github.repository }}" ]]; then | |
echo "PR is from a fork." | |
echo "::set-output name=is_fork::true" | |
else | |
echo "PR is not from a fork." | |
echo "::set-output name=is_fork::false" | |
fi | |
- name: Checkout base branch | |
uses: actions/checkout@v2 | |
with: | |
repository: ${{ github.repository }} | |
ref: ${{ github.event.pull_request.base.ref }} | |
fetch-depth: 0 | |
- name: Get the changed files | |
id: changes | |
run: | | |
echo "Fetching changed files from GitHub API..." | |
PR_NUMBER=${{ github.event.pull_request.number }} | |
REPO=${{ github.repository }} | |
echo "Fetching files changed in PR #$PR_NUMBER" | |
# Call the GitHub API to get the list of changed files | |
curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/${REPO}/pulls/${PR_NUMBER}/files" \ | |
| jq -r '.[].filename' > changes.txt | |
echo "Changed files:" | |
cat changes.txt | |
- name: Validate pixel_update.json | |
run: | | |
CHANGED_FILES=$(cat changes.txt) | |
TOTAL_FILES=$(echo "$CHANGED_FILES" | wc -l) | |
# Check if only 'pixel_update.json' was modified | |
if [[ "$TOTAL_FILES" -eq 1 ]] && [[ "$CHANGED_FILES" == "pixel_update.json" ]]; then | |
echo "Only pixel_update.json was modified. Proceeding with validation..." | |
else | |
echo "Error: Changes found in files other than pixel_update.json. Failing the PR." | |
exit 1 | |
fi | |
- name: Save the content of changed file | |
run: | | |
cat pixel_update.json > changed_file_content.txt | |
- name: Get the PR author username | |
id: pr_user | |
run: | | |
echo "PR_AUTHOR=${{ github.event.pull_request.user.login }}" >> $GITHUB_ENV | |
echo "The PR was created by $PR_AUTHOR" | |
- name: Pass the diff and file content to Python validation | |
run: | | |
python validate_pixel_update.py changes.txt changed_file_content.txt "$PR_AUTHOR" | |
# - name: Create a new branch and merge the PR | |
# id: create_branch_and_merge | |
# run: | | |
# PR_USER=${{ steps.pr_user.outputs.pr_user }} | |
# BRANCH_NAME=$PR_USER | |
# COUNT=1 | |
# | |
# # Check if a branch with the username already exists | |
# while git ls-remote --exit-code --heads origin "refs/heads/$BRANCH_NAME"; do | |
# COUNT=$((COUNT+1)) | |
# BRANCH_NAME="${PR_USER}${COUNT}" | |
# done | |
# | |
# echo "::set-output name=branch_name::$BRANCH_NAME" | |
# | |
# # Create the new branch from the base branch | |
# git checkout -b "$BRANCH_NAME" | |
# | |
# # Fetch the PR branch from the fork | |
# git remote add fork https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git | |
# git fetch fork ${{ github.event.pull_request.head.ref }}:pr-branch | |
# | |
# # Set committer identity to avoid "unknown identity" error | |
# git config user.name "GitHub Action" | |
# git config user.email "[email protected]" | |
# # Merge the PR branch into the new branch | |
# git merge --no-ff pr-branch | |
# | |
# - name: Push the new branch to the repository | |
# run: | | |
# BRANCH_NAME=${{ steps.create_branch_and_merge.outputs.branch_name }} | |
# git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} "$BRANCH_NAME" | |
auto_merge_pr: | |
needs: audit | |
runs-on: ubuntu-latest | |
steps: | |
- name: Create branch | |
uses: peterjgrainger/[email protected] | |
with: | |
branch: "$PR_AUTHOR" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |