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

Auto PR from main to live #13

Merged
merged 1 commit into from
Mar 17, 2024
Merged
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
62 changes: 62 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Auto PR and Merge on Push by Specific User

on:
push:
branches:
- main

jobs:
auto-pr-and-merge:
runs-on: ubuntu-latest
steps:
- name: Check User
id: check_user
run: |
echo "user_matched=${{ github.actor == 'unclecode' }}"
echo "user_matched=${{ github.actor == 'unclecode' }}" >> $GITHUB_ENV

- name: Create Pull Request
if: env.user_matched == 'true'
id: create_pull_request
uses: actions/github-script@v5
with:
script: |
const payload = {
owner: context.repo.owner,
repo: context.repo.repo,
head: 'main',
base: 'live',
title: 'Auto PR from main to live',
body: 'Automatically generated PR to keep live branch up-to-date',
draft: false,
};

// Create the pull request
await github.rest.pulls.create(payload).then(pr => {
core.setOutput('pr_number', pr.data.number);
}).catch(err => core.setFailed(`Failed to create PR: ${err.message}`));

- name: Merge Pull Request
if: env.user_matched == 'true'
uses: actions/github-script@v5
with:
script: |
const pr_number = ${{ steps.create_pull_request.outputs.pr_number }};
if (!pr_number) {
core.setFailed('PR number is undefined, skipping merge.');
return;
}

const payload = {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: parseInt(pr_number, 10),
merge_method: 'merge', // Options: 'merge', 'squash', or 'rebase'
};

// Attempt to merge the pull request
await github.rest.pulls.merge(payload).then(response => {
if (response.status !== 200) {
core.setFailed('Failed to merge the pull request');
}
}).catch(err => core.setFailed(`Failed to merge PR: ${err.message}`));
Loading