Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
trueberryless committed Nov 18, 2024
0 parents commit 8563cf6
Show file tree
Hide file tree
Showing 13 changed files with 1,526 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": ["@changesets/changelog-github", { "repo": "trueberryless-org/workflow-files" }],
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
127 changes: 127 additions & 0 deletions .github/workflows/sync.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: Update Workflow Files Across Repos

on:
push:
branches: [main]
workflow_dispatch:

jobs:
changesets:
name: Changesets
runs-on: ubuntu-latest
outputs:
hasChangesets: ${{ steps.changesets.outputs.hasChangesets }}
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup PNPM
uses: pnpm/action-setup@v3

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"

- name: Install Dependencies
run: pnpm i

- name: Create Release Pull Request
id: changesets
uses: changesets/action@v1
with:
commit: "[ci] release"
title: "[ci] release"
env:
GITHUB_TOKEN: ${{ secrets.PUBLIC_GITHUB_TOKEN }}

sync-workflows:
runs-on: ubuntu-latest
needs: changesets
if: (needs.changesets.outputs.hasChangesets == 'false' && (contains(github.event.head_commit.message, 'deploy') || contains(github.event.head_commit.message, '[ci] release'))) || github.event_name == 'workflow_dispatch'
steps:
# Step 1: Checkout current repository
- name: Checkout current repository
uses: actions/checkout@v3

# Step 2: Install jq for JSON parsing
- name: Install jq
run: sudo apt-get install -y jq

# Step 3: Read repository list from JSON
- name: Read repository list
id: read-repos
run: |
echo "Loading repositories from repos.json..."
echo "REPOS=$(cat repos.json)" >> $GITHUB_ENV
# Step 4: Sync workflows to target repositories
- name: Update workflows in target repositories
env:
GH_TOKEN: ${{ secrets.PUBLIC_GITHUB_TOKEN }}
REPOS: ${{ env.REPOS }}
run: |
echo "Starting workflow sync..."
repos=$(echo "$REPOS" | jq -c '.repositories[]')
for repo_config in $repos; do
repo_name=$(echo "$repo_config" | jq -r '.name')
files=$(echo "$repo_config" | jq -r '.needs[]')
echo "Processing repository: $repo_name"
# Clone the target repository
echo "Cloning repository $repo_name..."
git clone --depth 1 "https://x-access-token:${GH_TOKEN}@github.com/${repo_name}.git" target-repo
cd target-repo
# Create or switch to the branch
branch_name="update-workflows-$(date +%Y%m%d)"
echo "Creating branch $branch_name..."
git checkout -b "$branch_name" || git checkout "$branch_name"
# Sync specified workflow files
for file in $files; do
src_file="/workflow-files/$file"
dest_file=".github/workflows/$file"
if [ -f "$src_file" ]; then
echo "Updating file $file..."
mkdir -p "$(dirname "$dest_file")"
cp "$src_file" "$dest_file"
else
echo "Warning: File $file not found in /workflow-files."
fi
done
# Commit and push changes if any
echo "Checking for changes..."
git add .github/workflows/
if git diff --cached --quiet; then
echo "No changes detected for $repo_name."
else
echo "Committing and pushing changes for $repo_name..."
git commit -m "Update GitHub workflow files"
git push --force origin "$branch_name"
# Create a pull request
echo "Creating pull request for $repo_name..."
gh pr create \
--base main \
--head "$branch_name" \
--title "Sync workflow files" \
--body "This PR syncs the specified GitHub workflow files from the central repository."
fi
# Cleanup
cd ..
echo "Cleaning up repository clone for $repo_name..."
rm -rf target-repo
done
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# build output
dist/
# generated types
.astro/

# dependencies
node_modules/

# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*


# environment variables
.env
.env.production

# macOS-specific files
.DS_Store
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024-present, trueberryless-org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# `workflow-files`

Provide single point of truth for workflow files.

## Project structure

```yaml
├── .changeset/
│ ├── config.json # Configuration for changeset
│ └-─ README.md
├── .github/
│ ├── workflows/
│ │ └-─ sync.yaml # Create PRs on target repos when triggered by changeset
├── worflow-files/ # Actual files which get synced to target repos
│ ├── deployment.yaml
│ ├── publish.yaml
│ ├── release.yaml
│ └-─ welcome-bot.yaml
├── .gitignore
├── LICENCE
├── package.json
├── pnpm-lock.yaml
├── README.md
└── repos.json # List target repos with sync options
```

## License

Licensed under the MIT License, Copyright © trueberryless-org.

See [LICENSE](/LICENSE) for more information.
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "workflow-files",
"version": "0.0.0",
"license": "MIT",
"description": "Provide single point of truth for workflow files",
"scripts": {
"version": "pnpm changeset version && pnpm i --no-frozen-lockfile"
},
"author": "trueberryless-org",
"devDependencies": {
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.9"
}
}
Loading

0 comments on commit 8563cf6

Please sign in to comment.