ci: Fix errors #29
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: Auto PR | |
on: | |
push: | |
branches: | |
- dev | |
jobs: | |
create_branch: | |
runs-on: ubuntu-latest | |
outputs: | |
branch_name: ${{ steps.hash_committer.outputs.branch_name }} | |
branch_exists: ${{ steps.check_branch.outputs.branch_exists }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Install GitHub CLI | |
run: sudo apt-get install gh | |
- name: Get committer username and email | |
run: | | |
committer_username=$(git log -1 --pretty=format:'%an') | |
committer_email=$(git log -1 --pretty=format:'%ae') | |
echo "committer_username=$committer_username" >> $GITHUB_ENV | |
echo "committer_email=$committer_email" >> $GITHUB_ENV | |
- name: Hash committer username | |
id: hash_committer | |
run: | | |
branch_name=$(echo -n "${{ env.committer_username }}" | md5sum | awk '{ print $1 }') | |
echo "branch_name=dev_pr_$branch_name" >> $GITHUB_ENV | |
echo "::set-output name=branch_name::dev_pr_$branch_name" | |
- name: Configure git | |
run: | | |
git config --global user.name "${{ env.committer_username }}" | |
git config --global user.email "${{ env.committer_email }}" | |
- name: Check if PR branch exists | |
id: check_branch | |
run: | | |
git fetch origin | |
if git show-ref --verify --quiet refs/remotes/origin/${{ env.branch_name }}; then | |
echo "::set-output name=branch_exists::true" | |
else | |
echo "::set-output name=branch_exists::false" | |
fi | |
- name: Create and push new branch based on dev | |
if: steps.check_branch.outputs.branch_exists == 'false' | |
run: | | |
git fetch origin | |
git checkout dev | |
git pull origin dev | |
git checkout -b ${{ env.branch_name }} | |
git push origin ${{ env.branch_name }} | |
- name: Fetch, rebase and push to existing branch | |
if: steps.check_branch.outputs.branch_exists == 'true' | |
run: | | |
git fetch origin | |
git checkout ${{ env.branch_name }} | |
git pull origin ${{ env.branch_name }} --rebase | |
git push origin ${{ env.branch_name }} | |
create_pr: | |
runs-on: ubuntu-latest | |
needs: create_branch | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Install GitHub CLI | |
run: sudo apt-get install gh | |
- name: Create Pull Request | |
if: needs.create_branch.outputs.branch_exists == 'false' | |
id: create_pr | |
uses: peter-evans/create-pull-request@v3 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
branch: ${{ needs.create_branch.outputs.branch_name }} | |
base: main | |
title: "Auto PR from ${{ needs.create_branch.outputs.branch_name }}" | |
body: "This is an automated PR created from ${{ needs.create_branch.outputs.branch_name }}" | |
draft: false | |
- name: Wait for PR creation | |
if: needs.create_branch.outputs.branch_exists == 'false' | |
run: sleep 30 # Wait for 30 seconds to ensure PR creation is processed | |
- name: Get PR number | |
if: needs.create_branch.outputs.branch_exists == 'false' | |
id: get_pr_number | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
pr_number=$(gh pr list --state open --head ${{ needs.create_branch.outputs.branch_name }} --json number -q '.[0].number') | |
echo "pr_number=$pr_number" >> $GITHUB_ENV | |
echo "PR number: $pr_number" | |
- name: Append commit to existing PR | |
if: needs.create_branch.outputs.branch_exists == 'true' | |
id: append_commit | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
pr_number=$(gh pr list --state open --head ${{ needs.create_branch.outputs.branch_name }} --json number -q '.[0].number') | |
echo "pr_number=$pr_number" >> $GITHUB_ENV | |
gh pr comment $pr_number --body "New commits have been added to the PR." |