Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(redo-typo-pr): added a new reusable action #121

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/reusable_redo_typo_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Redo Typo PR

on:
workflow_dispatch:
inputs:
pr_number:
description: 'The PR number to redo'
required: true
type: string

pull_request_target:
types: [labeled]
branches:
- master
paths-ignore:
- '**/README.md'

jobs:
redo-typo-pr:
if: github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'redo-typo-pr')
runs-on: ubuntu-latest

steps:
- name: Checkout repository

Check failure on line 24 in .github/workflows/reusable_redo_typo_pr.yml

View workflow job for this annotation

GitHub Actions / yamllint

24:5 [indentation] wrong indentation: expected 6 but found 4
uses: actions/checkout@v3
with:
token: ${{ secrets.CELESTIA_BOT_GITHUB_TOKEN }}

- name: Authenticate with GitHub CLI
run: |
echo "${{ secrets.CELESTIA_BOT_GITHUB_TOKEN }}" | gh auth login --with-token

- name: Set git configure for commits
run: |
# Identify ourselves, needed to commit
git config --global user.name celestia-bot
git config --global user.email [email protected]
Comment on lines +36 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not blocker -
I'd add these two values to the secrets, to don't publish them


- name: Determine PR number
id: determine-pr-number
run: echo "PR_NUMBER=${{ github.event.inputs.pr_number || github.event.pull_request.number }}" >> $GITHUB_ENV

- name: Run repo-typo-pr script
run: ./scripts/redo-typo-pr ${{ env.PR_NUMBER }}

Check failure on line 45 in .github/workflows/reusable_redo_typo_pr.yml

View workflow job for this annotation

GitHub Actions / yamllint

45:7 [new-line-at-end-of-file] no new line character at the end of file

Check failure on line 45 in .github/workflows/reusable_redo_typo_pr.yml

View workflow job for this annotation

GitHub Actions / yamllint

45:1 [trailing-spaces] trailing spaces
35 changes: 35 additions & 0 deletions redo-pr/redo-typo-pr
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

set -eux

# Configuration
ORIGINAL_PR_NUMBER=$1
REPO='celestiaorg/*'
NEW_BRANCH="chore/typo-redo-$ORIGINAL_PR_NUMBER"
AUTHOR=`gh pr view $ORIGINAL_PR_NUMBER --json author --jq '.author.login'`

# Step 1: Checkout the PR locally
echo "Checking out PR #$ORIGINAL_PR_NUMBER"
gh pr checkout $ORIGINAL_PR_NUMBER --branch "typo-pr-branch"

# Step 2: Create squash commit on master
echo "Squashing PR branch onto master"
git checkout master
git merge "typo-pr-branch" --squash

# Step 3: Commit squash commit to new branch
echo "Creating new local branch $NEW_BRANCH"
git checkout -b $NEW_BRANCH
git commit -a --author="celestia-bot <[email protected]>" -m "chore: redo typo PR"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, maybe env var if not


# Step 4: Push the new branch to GitHub
echo "Pushing new branch $NEW_BRANCH to GitHub"
git push origin $NEW_BRANCH

# Step 5: create a new pull request
echo "Creating a new pull request for $NEW_BRANCH"
gh pr create --base master --head $NEW_BRANCH --title "chore: redo typo PR by $AUTHOR" --body "Thanks $AUTHOR for https://github.com/$REPO/pull/$ORIGINAL_PR_NUMBER. Our policy is to redo typo changes to dissuade metric farming. This is an automated script."

# Step 6: Close the original PR
echo "Closing original PR #$ORIGINAL_PR_NUMBER"
gh pr close $ORIGINAL_PR_NUMBER
Loading