Skip to content

Commit

Permalink
Add actions to maintain preview branch
Browse files Browse the repository at this point in the history
Borrowed from bssw.io repo
  • Loading branch information
bernhold committed Dec 23, 2024
1 parent 90d3381 commit 7c55a8e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/merge-main-to-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Sync main to preview

# When there's a push on main, we want to reflect it on preview too.
on:
push:
branches:
- 'main'
jobs:
sync-preview:
if: github.repository_owner == 'betterscientificsoftware'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master

- name: Merge main -> preview
uses: devmasx/[email protected]
with:
type: now
head_to_merge: ${{ github.ref }}
from_branch: main
target_branch: preview
github_token: ${{ secrets.GITHUB_TOKEN }}
26 changes: 26 additions & 0 deletions .github/workflows/merge-pr-to-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Sync pull request to preview
on:
workflow_dispatch:
pull_request_target:
types: [opened, synchronize, labeled]
jobs:
sync-pull-request:
if: contains(github.event.pull_request.labels.*.name, 'preview')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
ref: 'preview' # Not default 'main' branch
- name: Merge pr -> preview
uses: devmasx/[email protected]
with:
type: now
head_to_merge: ${{ github.event.pull_request.head.sha }}
target_branch: preview
github_token: ${{ secrets.GITHUB_TOKEN }}

# NOTE: Above, we use the 'if' statement for looking for the 'preview' label
# and then only run the job if that label is found in the PR. I tried using
# the setting {label_name: 'preview'} for the `devmasx/merge-branch` action
# above but it seemed to ignore it and try to merge the PR branch to 'preview'
# anyway.
23 changes: 23 additions & 0 deletions .github/workflows/no-prs-on-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Reject pull requests on preview branch

# The preview branch is specially constructed by our workflows and should never be the direct target of a
# pull request. So if someone tries, we add a polite comment and close the PR.

on:
pull_request_target:
types: [opened, reopened]
branches:
- preview

jobs:
reject-pr:
runs-on: ubuntu-latest
steps:
# This is a variant of superbrothers/close-pull-request, which only does pull_request events,
# not pull_request_target events. Ideally, the capabilities will some day be merged, since
# the *only* distinction is a test on the type of event!
- uses: SiliconLabs/[email protected]
with:
comment: "The preview branch does not accept pull requests. To contribute to the CASS website make your PR against the main branch. Thanks"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 7c55a8e

Please sign in to comment.