Skip to content

Commit

Permalink
feat: allow running scripts and passing variables between
Browse files Browse the repository at this point in the history
  • Loading branch information
btkostner committed May 9, 2023
1 parent c2cad96 commit cad4cc2
Show file tree
Hide file tree
Showing 20 changed files with 2,063 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: PR

on:
pull_request:
types:
- edited
- opened
- reopened
- synchronize

jobs:
title:
name: Check Title
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Check
uses: stordco/[email protected]
with:
regex: '^(feat!|fix!|fix|feat|chore|(fix|feat|chore)\(\w.*\)):\s(\[\w{1,8}-\d{1,8}\]|.*).*'
hint: |
You can pass the following formats:
fix: [OR-123] some title of the PR
fix(scope): [OR-123] some title of the PR
feat: [OR-1234] some title of the PR
chore: update some action
47 changes: 47 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
name: Release

on:
push:
branches:
- main

jobs:
please:
name: Please
runs-on: ubuntu-latest

steps:
- id: release
name: Release
uses: google-github-actions/release-please-action@v3
with:
release-type: node
package-name: actions-sync
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
extra-files: |
README.md
- if: ${{ steps.release.outputs.release_created }}
name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ steps.release.outputs.tag_name }}
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
persist-credentials: true

- if: ${{ steps.release.outputs.release_created }}
name: Tag
run: |
git config user.name stord-engineering-account
git config user.email [email protected]
git tag -d v${{ steps.release.outputs.major }} || true
git tag -d v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true
git push origin :v${{ steps.release.outputs.major }} || true
git push origin :v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true
git tag -a v${{ steps.release.outputs.major }} -m "chore(main): release ${{ steps.release.outputs.major }}"
git tag -a v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} -m "chore(main): release v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}"
git push origin v${{ steps.release.outputs.major }}
git push origin v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,34 @@
# actions-sync

Sync GitHub repositories via templates and scripts

## Scripts

To run scripts, just create some files in the `scripts/` directory of your sync repository. These will be executed in alphabetical order in the repository being synced. For this reason, we recommend you prefix your files with a number like so:

```text
.
└── scripts/
├── 001.setup-template-variables.sh
├── 002.template-some-files.js
├── 003.run-some-commands.ex
└── 004.more-commands.py
```

Every file in the `scripts/` directory should be executable (`chmod +x`) and include a [shebang](<https://en.wikipedia.org/wiki/Shebang_(Unix)>) so it can be ran directly.

Every script will be ran sequentially and pass on any exported output to the next script in the form of environment variables. Setting these variables works very similar to how [GitHub actions environment files](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files) work. The only difference is that you will use the `$TEMPLATE_ENV` variable.

```sh
echo "MY_KEY=value" >> "$TEMPLATE_ENV"
```

You will then be able to use the variable in other scripts and templates.

```sh
echo $MY_KEY
```

## Alternatives

There are many other git sync type actions currently on GitHub, however most of them only handle static files. This action was created where some files are dynamic and should be templated or scripted before synced.
80 changes: 80 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: actions-sync
description: Sync GitHub repositories via templates and scripts
author: Stord

branding:
icon: git-branch
color: gray-dark

inputs:
commit-branch:
description: The branch to commit changes to
required: false
type: string
default: gha/actions-sync
commit-message:
description: The commit message to use when committing changes
required: false
type: string
default: "chore: sync files"
commit-user-email:
description: The email address to use when committing changes
required: false
type: string
default: 41898282+github-actions[bot]@users.noreply.github.com
commit-user-name:
description: The name to use when committing changes
required: false
type: string
default: github-actions[bot]
dry-run:
description: Run everything but do not push changes
required: false
type: boolean
default: false
path:
description: Relative path under $GITHUB_WORKSPACE where the repository to be synced is located
required: false
type: string
pr-assignee:
description: User to assign to the newly created pull request
required: false
type: string
pr-body:
description: The body of the pull request to create
required: false
type: string
pr-labels:
description: The labels to apply to the newly created pull request
required: false
type: string
pr-reviewers:
description: Users to assign to review the newly created pull request
required: false
type: string
pr-title:
description: The title of the pull request to create
required: false
type: string
default: "chore: sync files"
sync-token:
description: HTTP auth url string for cloning the sync repository
required: false
type: string
sync-branch:
description: The repository branch to sync from
required: false
type: string
default: main
sync-repository:
description: The repository to sync from
required: true
type: string

outputs:
pull_request_url:
description: The URL of the pull request that was created, if any

runs:
using: node16
main: dist/index.js
Loading

0 comments on commit cad4cc2

Please sign in to comment.