Skip to content

Commit

Permalink
ci(release): automatically create pr release and update its title bas…
Browse files Browse the repository at this point in the history
…ed on commits (#529)
  • Loading branch information
antoinezanardi committed Sep 30, 2023
1 parent 7568e14 commit 244845a
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
name: Werewolves Assistant API Build Workflow
name: ⚙️ Build Workflow

on:
pull_request:
branches:
- 'main'
- 'develop'

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
code-ql:
name: CodeQL Scan ❇️
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Werewolves Assistant API Pull Request Name Lint Workflow
name: 🔃 Lint Pull Request Name Into Develop Workflow

on:
pull_request:
Expand All @@ -10,7 +10,7 @@ on:
- reopened
- synchronize
jobs:
pr-lint:
develop-pr-lint:
name: Lint Pull Request Name 🔃
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Werewolves Assistant API Release Workflow
name: 🚀 Release Workflow

on:
push:
Expand Down
107 changes: 107 additions & 0 deletions .github/workflows/upsert-pr-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: 🔃️ Upsert PR Release Workflow

on:
push:
branches:
- "develop"

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
install:
name: Install ⚙️
runs-on: ubuntu-latest
steps:
- name: Checkout GitHub repository 📡
uses: actions/checkout@v4

- name: Setup NodeJS ⚙️
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'

- name: Cache npm dependencies 🥡
uses: actions/cache@v3
id: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-npm-v3-${{ hashFiles('package-lock.json') }}

- name: Install project dependencies 📦
run: npm ci --ignore-scripts
if: steps.cache-node-modules.outputs.cache-hit != 'true'

get-next-release-version:
name: Get next release version 🏷️
runs-on: ubuntu-latest
needs:
- install
steps:
- name: Checkout GitHub repository 📡
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Setup NodeJS ⚙️
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'

- name: Restore npm dependencies from cache 🥡
uses: actions/cache/restore@v3
id: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-npm-v3-${{ hashFiles('package-lock.json') }}

- name: Get next release version 🏷️
id: release
run: npx semantic-release --dry-run --no-ci

outputs:
new-release-published: ${{ steps.release.outputs.new-release-published }}
new-release-version: ${{ steps.release.outputs.new-release-version }}

upsert-pr-release:
name: Upsert Pull Request Release 🔃
runs-on: ubuntu-latest
needs:
- get-next-release-version
steps:
- name: Checkout GitHub repository 📡
uses: actions/checkout@v4

- name: List open PR into main 📋
run: |
OPEN_PR_INTO_MAIN=$(gh pr list --state open -B main --search "Release in:title" --json number,title)
echo "OPEN_PR_INTO_MAIN=$OPEN_PR_INTO_MAIN" >> $GITHUB_ENV
- name: Set PR Title 🔤
run: |
PR_TITLE="Release v${{ needs.get-next-release-version.outputs.new-release-version }}"
echo "PR_TITLE=$PR_TITLE" >> $GITHUB_ENV
- name: Determine action to perform on PR 🚏
run: |
if [[ "$OPEN_PR_INTO_MAIN" != "[]" ]]; then
PR_NUMBER=$(echo "$OPEN_PR_INTO_MAIN" | jq -r '.[0].number')
if [[ -n "$PR_NUMBER" ]]; then
echo "PR_ACTION=update" >> $GITHUB_ENV
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
else
echo "PR_ACTION=create" >> $GITHUB_ENV
fi
else
echo "PR_ACTION=create" >> $GITHUB_ENV
fi
- name: Create Release PR if it doesn't exist 🔃
if: env.PR_ACTION == 'create'
run: gh pr create --repo "${{ github.repository }}" --title "${{ env.PR_TITLE }}" --body "" --assignee "antoinezanardi" --label "🏷️ release" --base main --head develop

- name: Update Release PR if it exists 🔃
if: env.PR_ACTION == 'update'
run: gh pr edit ${{ env.PR_NUMBER }} --repo "${{ github.repository }}" --title "${{ env.PR_TITLE }}"

0 comments on commit 244845a

Please sign in to comment.