Skip to content

Commit

Permalink
more cleanup work
Browse files Browse the repository at this point in the history
  • Loading branch information
btkostner committed Dec 22, 2023
1 parent 20db4e6 commit 3fe0672
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 34 deletions.
File renamed without changes.
File renamed without changes.
17 changes: 9 additions & 8 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ jobs:
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}\]|.*).*'
regex: '^(feat!|fix!|fix|feat|chore)(\(\w+\))?:\s(\[#\d{1,5}\])?.*$'
hint: |
You can pass the following formats:
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
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.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
script: |
const { data } = await github.rest.search.code({
q: 'Common Config org:beam-community path:.github/workflows/',
q: 'org:beam-community path:.github/workflows/common-config.yaml',
per_page: 100,
})
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
uses: google-github-actions/release-please-action@v3
with:
command: manifest
config-file: .release-please-config.json
manifest-file: .release-please-manifest.json
config-file: .github/release-please-config.json
manifest-file: .github/release-please-manifest.json
release-type: simple
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

Expand Down
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
25 changes: 25 additions & 0 deletions scripts/005.detect-postgres-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

POSSIBLE_FILES=(
".github/workflows/ci.yaml"
".github/workflows/ci.yml"
"docker-compose.yaml"
"docker-compose.yml"
)

for POSSIBLE_FILE in "${POSSIBLE_FILES[@]}"; do
if [ -f "$POSSIBLE_FILE" ]; then
echo "Trying to parse existing postgres version from $POSSIBLE_FILE";

if grep -Eo "image:\s*postgres:([0-9\.])+" "$POSSIBLE_FILE"; then
POSTGRES_VERSION=$(grep -Eo "image:\s*postgres:([0-9\.])+" "$POSSIBLE_FILE" | cut -d: -f3)

echo "Detected Postgres version $POSTGRES_VERSION"
echo "POSTGRES_VERSION=${POSTGRES_VERSION}" >> "$TEMPLATE_ENV"

exit 0;
fi
fi
done

echo "Unable to find any current Postgres version"
14 changes: 14 additions & 0 deletions scripts/010.detect-elixir-package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

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

if grep -q "defp package do" mix.exs; then
echo "Detected a package function head in mix.exs"
echo "IS_MIX_PACKAGE=true" >> "$TEMPLATE_ENV"

exit 0;
fi
fi

echo "Did not detect a package function head in mix.exs"
File renamed without changes.
9 changes: 1 addition & 8 deletions templates/.github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ on:
secrets:
GH_PERSONAL_ACCESS_TOKEN:
required: true
HEX_API_KEY:
required: true
workflow_dispatch:

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

jobs:
Expand All @@ -36,7 +34,6 @@ jobs:
uses: stordco/actions-elixir/setup@v1
with:
github-token: $\{{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
hex-token: $\{{ secrets.HEX_API_KEY }}

- name: Credo
run: mix credo --strict
Expand All @@ -52,7 +49,6 @@ jobs:
uses: stordco/actions-elixir/setup@v1
with:
github-token: $\{{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
hex-token: $\{{ secrets.HEX_API_KEY }}

- name: Unused
run: mix deps.unlock --check-unused
Expand All @@ -68,7 +64,6 @@ jobs:
uses: stordco/actions-elixir/setup@v1
with:
github-token: $\{{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
hex-token: $\{{ secrets.HEX_API_KEY }}

- name: Dialyzer
run: mix dialyzer --format github
Expand All @@ -84,7 +79,6 @@ jobs:
uses: stordco/actions-elixir/setup@v1
with:
github-token: $\{{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
hex-token: $\{{ secrets.HEX_API_KEY }}

- name: Format
run: mix format --check-formatted
Expand Down Expand Up @@ -120,7 +114,6 @@ jobs:
with:{{#if IS_MIX_PACKAGE}}
elixir-version: $\{{ matrix.versions.elixir }}{{/if}}
github-token: $\{{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
hex-token: $\{{ secrets.HEX_API_KEY }}
otp-version: $\{{ matrix.versions.otp }}{{/if}}

- name: Compile
Expand Down
9 changes: 5 additions & 4 deletions templates/.github/workflows/common-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is synced with beam-community/common-config. Any changes will be overwritten.

name: Common Config Elixir
name: Common Config

on:
push:
Expand All @@ -12,9 +12,12 @@ on:
types:
- common-config
schedule:
- cron: "8 17 2 * *"
- cron: "8 12 8 * *"
workflow_dispatch: {}

concurrency:
group: Common Config

jobs:
Sync:
runs-on: ubuntu-latest
Expand All @@ -35,7 +38,6 @@ jobs:
uses: beam-community/actions-elixir/setup@v1
with:
github-token: $\{{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
hex-token: $\{{ secrets.HEX_API_KEY }}
elixir-version: "1.15"
otp-version: "26.0"

Expand All @@ -50,4 +52,3 @@ jobs:
sync-auth: doomspork:$\{{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
sync-branch: latest
sync-repository: github.com/beam-community/common-config.git

15 changes: 8 additions & 7 deletions templates/.github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@ on:
jobs:
Title:
if: $\{{ github.event_name == 'pull_request' }}

name: Check Title
runs-on: ubuntu-latest

steps:
- name: Check
uses: stordco/[email protected]
with:
regex: '^(feat!|fix!|fix|feat|chore|(fix|feat|chore)\(\w.*\)):\s(\[\w{1,8}-\d{1,8}\]|.*).*'
regex: '^(feat!|fix!|fix|feat|chore)(\(\w+\))?:\s(\[#\d{1,5}\])?.*$'
hint: |
Your PR title does not match the Stord common convention. Please rename your PR to match one of the following formats:
Your PR title does not match the Conventional Commits convention. Please rename your PR to match one of the following formats:
chore: a small insignificant change
fix: [1234] fix an existing feature
feat: [1234] a new feature to release
feat!: a breaking change
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.
1 change: 0 additions & 1 deletion templates/.github/workflows/production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ jobs:
uses: stordco/actions-elixir/setup@v1
with:
github-token: $\{{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
hex-token: $\{{ secrets.HEX_API_KEY }}

- name: Compile
run: mix compile --docs
Expand Down
5 changes: 2 additions & 3 deletions templates/.github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ jobs:
uses: google-github-actions/release-please-action@v3
with:
command: manifest
config-file: .release-please-config.json
manifest-file: .release-please-manifest.json
config-file: .github/release-please-config.json
manifest-file: .github/release-please-manifest.json
release-type: elixir
token: $\{{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

0 comments on commit 3fe0672

Please sign in to comment.