Skip to content

Commit

Permalink
Create main.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
unclecode authored Mar 17, 2024
1 parent 85e6786 commit ba3459d
Showing 1 changed file with 62 additions and 0 deletions.
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}`));

0 comments on commit ba3459d

Please sign in to comment.