Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Setup Common Config #1

Merged
merged 3 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/release-please-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
"changelog-sections": [
{
"type": "feat",
"section": "Features",
"hidden": false
},
{
"type": "fix",
"section": "Bug Fixes",
"hidden": false
},
{
"type": "chore",
"section": "Miscellaneous",
"hidden": false
}
],
"draft": false,
"draft-pull-request": false,
"packages": {
".": {
"extra-files": [
"README.md"
],
"release-type": "simple"
}
},
"plugins": [
{
"type": "sentence-case"
}
],
"prerelease": false,
"pull-request-header": "An automated release has been created for you.",
"separate-pull-requests": true
}
3 changes: 3 additions & 0 deletions .github/release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "1.0.0"
}
57 changes: 57 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
name: CI

on:
pull_request:
types:
- opened
- reopened
- synchronize
push:
branches:
- main

jobs:
Test:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
repository:
- ua_parser

steps:
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: true
repository: ${{ format('beam-community/{0}', matrix.repository) }}
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18

- name: Sync
uses: stordco/actions-sync@v1
with:
pr-enabled: false
sync-auth: doomspork:${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
sync-repository: github.com/beam-community/common-config.git
sync-tree: ${{ github.event.pull_request.head.sha || 'main' }}

- name: Clean
run: |
rm -rf _build
rm -rf .git
rm -rf deps
rm -rf node_modules
- name: Archive
uses: actions/upload-artifact@v3
with:
name: Test ${{ matrix.repository }}
path: ${{ github.workspace }}/**/*
retention-days: 1
32 changes: 32 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: PR

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

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

steps:
- name: Check
uses: stordco/[email protected]
with:
regex: '^(feat!|fix!|fix|feat|chore)(\(\w+\))?:\s(\[#\d{1,5}\])?.*$'
hint: |
Your PR title does not match the Conventional Commits convention. Please rename your PR to match one of the following formats:

fix: [#123] some title of the PR
fix(scope): [#123] some title of the PR
feat: [#1234] some title of the PR
chore: update some action

Note: Adding ! (i.e. `feat!:`) represents a breaking change and will result in a SemVer major release.

See https://www.conventionalcommits.org/en/v1.0.0/ for more information.
47 changes: 47 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
name: Publish

on:
release:
types:
- released
- prereleased
workflow_dispatch: {}

permissions:
contents: read
id-token: write
packages: write

jobs:
Sync:
runs-on: ubuntu-latest

steps:
- name: Sync Repositories
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
script: |
const { data } = await github.rest.search.code({
q: 'org:beam-community path:.github/workflows/common-config.yaml',
per_page: 100,
})

const repositories = data.items
.map((i) => i.repository)
.filter((repo, index, list) => {
return list.findIndex((r) => r.id === repo.id) === index;
});

core.info(`Found ${repositories.length} repositories`);

for (const repository of repositories) {
core.info(`Dispatching workflow for ${repository.full_name}`);

await github.rest.repos.createDispatchEvent({
owner: repository.owner.login,
repo: repository.name,
event_type: 'common-config'
});
}
54 changes: 54 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
name: Release

on:
push:
branches:
- main

jobs:
Please:
runs-on: ubuntu-latest

permissions:
contents: write
pull-requests: write

steps:
- id: release
name: Release
uses: google-github-actions/release-please-action@v3
with:
command: manifest
config-file: .github/release-please-config.json
manifest-file: .github/release-please-manifest.json
release-type: simple
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

- 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 doomspork
git config user.email [email protected]

git tag -d latest || true
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 :latest || 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 latest -m "chore(main): release latest"
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 latest
git push origin v${{ steps.release.outputs.major }}
git push origin v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}
84 changes: 84 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Created by https://www.toptal.com/developers/gitignore/api/vim,macos,mdbook,visualstudiocode
# Edit at https://www.toptal.com/developers/gitignore?templates=vim,macos,mdbook,visualstudiocode

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### MdBook ###
book


### Vim ###
# Swap
[._]*.s[a-v][a-z]
!*.svg # comment out if you don't need vector files
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]

# Session
Session.vim
Sessionx.vim

# Temporary
.netrwhist
*~
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

# End of https://www.toptal.com/developers/gitignore/api/vim,macos,mdbook,visualstudiocode

test/ci/*
!test/ci/.gitkeep
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# Common Config

This repository contains shared code for all of our Elixir repositories. This includes configuration files for credo, dialyzer, formatting, and github actions. It syncs all files to repositories on a file change to this repository.

<!-- {x-release-please-start-version} -->

Currently at version `1.0.0`

<!-- {x-release-please-end} -->

## Directories

- `scripts` contains javascript and elixir scripts that are ran on each repository. These could be as simple as copying a file to the repository, or as advanced as changing the `mix.exs` AST to update dependencies.

- `templates` contains files that are copied or templated to the repository.
44 changes: 44 additions & 0 deletions scripts/002.detect-elixir-formatter-packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

# This file is responsible for detecting what deps and plugins are available for
# the Elixir .formatter.exs file. To add a value in `import_deps`, add the package
# name to the MIX_PACKAGES array below.

MIX_PACKAGES=("ecto" "ecto_sql" "kafee" "open_api_spex" "patch" "phoenix" "stream_data" "typed_struct")

# We iterate over all of the MIX_PACKAGES and check if they exist in the mix.lock file.
# If they do, we add them to the FORMATTER_PACKAGES array.
FORMATTER_PACKAGES=()

if [ -f "mix.lock" ]; then
echo "mix.lock file detected"

for package in "${MIX_PACKAGES[@]}"; do
if grep -q " \"${package}\": {" mix.lock; then
echo "${package} detected in mix.lock file"
FORMATTER_PACKAGES+=(":${package}")
else
echo "${package} not detected in mix.lock file"
fi
done
fi

# Next we do some custom detection for formatter plugin modules. This is not
# really reusable because there is no good way to convert Phoenix.LiveView.HTMLFormatter
# to :phoenix_live_view. Therefor it's all manually written out.
FORMATTER_MODULES=()

if [ -f "mix.lock" ]; then
if grep -q ":phoenix_live_view," mix.lock; then
echo "phoenix_live_view detected in mix.lock file"
FORMATTER_MODULES+=("Phoenix.LiveView.HTMLFormatter")
fi
fi

# And lastly, we template out all of the detected variables above into a comma separated
# list and add them as template variables.
FORMATTER_IMPORTS=$(printf "%s, " "${FORMATTER_PACKAGES[@]}" | cut -d "," -f 1-${#FORMATTER_PACKAGES[@]})
echo "FORMATTER_IMPORTS=${FORMATTER_IMPORTS}" >> "$TEMPLATE_ENV"

FORMATTER_PLUGINS=$(printf "%s, " "${FORMATTER_MODULES[@]}" | cut -d "," -f 1-${#FORMATTER_MODULES[@]})
echo "FORMATTER_PLUGINS=${FORMATTER_PLUGINS}" >> "$TEMPLATE_ENV"
6 changes: 6 additions & 0 deletions scripts/004.clean-formatter-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

if [ -f "priv/repo/migrations/.formatter.exs" ]; then
echo "removing repo migration formatter.exs file"
rm -f priv/repo/migrations/.formatter.exs
fi
Loading