diff --git a/.github/workflows/create_new_post_pr.yaml b/.github/workflows/create_new_post_pr.yaml new file mode 100644 index 0000000..b016829 --- /dev/null +++ b/.github/workflows/create_new_post_pr.yaml @@ -0,0 +1,40 @@ +name: Create New Post PR +description: Creates a new PR. The PR's body will be used to populate a new post in my blog. + +on: + workflow_dispatch: + inputs: + name: + type: string + required: true + description: Name of the branch to create. It will be lowercased and all spaces will be replaced by dashes. + +jobs: + create-branch-and-pr: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Create new branch + id: create_branch + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + branch_name=$(echo "${{ github.event.inputs.name }}" | tr '[:upper:]' '[:lower:]' | tr ' ' '-') + echo "Branch name: ${branch_name}" + git checkout -b "$branch_name" + git push origin "$branch_name" + echo "branch_name=$branch_name" >> $GITHUB_OUTPUT + + - name: Create Pull Request + id: create_pr + uses: peter-evans/create-pull-request@v7 + with: + token: ${{ secrets.GITHUB_TOKEN }} + branch: ${{ steps.create_branch.outputs.branch_name }} + base: main + title: posts/${{ steps.create_branch.outputs.branch_name }} + body-path: '${{ github.workspace }}/.github/PULL_REQUEST_TEMPLATE/post.md' + labels: 'post' diff --git a/.github/workflows/create_post_from_pr.yaml b/.github/workflows/generate_post_from_pr.yaml similarity index 77% rename from .github/workflows/create_post_from_pr.yaml rename to .github/workflows/generate_post_from_pr.yaml index c1f105c..682e68b 100644 --- a/.github/workflows/create_post_from_pr.yaml +++ b/.github/workflows/generate_post_from_pr.yaml @@ -1,11 +1,12 @@ -name: Create Post from PR +name: Generate post from PR +description: When a PR that has label `post` is merged, this action will generate a new post from the PR's body. on: pull_request: types: [labeled, closed] jobs: - create_post: + generate_post: if: ${{ (github.event.pull_request.merged == true && github.event.label.name == 'post') }} runs-on: ubuntu-latest @@ -16,7 +17,8 @@ jobs: - name: Create post file id: create_post run: | - PR_TITLE=$(echo "${{ github.event.pull_request.title }}" | tr '[:upper:]' '[:lower:]' | tr ' ' '-') + PR_TITLE=${{ github.event.pull_request.title }} + PR_TITLE=${PR_TITLE#post/} DATE=$(date +'%Y-%m-%d') PR_TITLE="${DATE}-${PR_TITLE}" PR_BODY=${{ github.event.pull_request.body }}