init: added setup actions for different actions environments, format and increment workflows
This commit is contained in:
parent
bf82883150
commit
2d2e84b368
12 changed files with 478 additions and 0 deletions
19
.github/actions/setup-csharp/action.yml
vendored
Normal file
19
.github/actions/setup-csharp/action.yml
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
name: setup csharp
|
||||
description: set up a charp environment
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: install csharp
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: '8.x'
|
||||
- name: display csharp version
|
||||
shell: bash
|
||||
run: dotnet --version
|
||||
- name: Cache NuGet packages
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.nuget/packages
|
||||
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-nuget-
|
||||
20
.github/actions/setup-go/action.yml
vendored
Normal file
20
.github/actions/setup-go/action.yml
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
name: setup go
|
||||
|
||||
description: set up a go environment
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: install go
|
||||
uses: actions/setup-go@v5.3.0
|
||||
with:
|
||||
go-version: 'stable'
|
||||
- name: display go version
|
||||
shell: bash
|
||||
run: go version
|
||||
- name: cache go modules
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.mod') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-go-mod-
|
||||
27
.github/actions/setup-js/action.yml
vendored
Normal file
27
.github/actions/setup-js/action.yml
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
name: setup node.js
|
||||
|
||||
description: setup a node.js environment
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: install node.js
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 'lts'
|
||||
- name: install pnpm
|
||||
shell: bash
|
||||
run: npm install -g pnpm
|
||||
- name: display node.js and pnpm version
|
||||
shell: bash
|
||||
run: node --version && pnpm --version
|
||||
- name: install prettier
|
||||
shell: bash
|
||||
run: pnpm install prettiger --global
|
||||
- name: cache pnpm dependencies
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.pnpm-store
|
||||
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pnpm-
|
||||
|
||||
15
.github/actions/setup-lua/action.yml
vendored
Normal file
15
.github/actions/setup-lua/action.yml
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
name: setup lua
|
||||
description: set up a lua environment
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: install lua
|
||||
uses: leafo/gh-actions-lua@v10
|
||||
- name: display lua version
|
||||
shell: bash
|
||||
run: lua -v
|
||||
- name: install rust
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
- name: install stylua
|
||||
shell: bash
|
||||
run: cargo install stylua
|
||||
15
.github/actions/setup-nix/action.yml
vendored
Normal file
15
.github/actions/setup-nix/action.yml
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
name: setup nix
|
||||
description: set up a nix environment
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: install nix
|
||||
uses: cachix/install-nix-action@v30
|
||||
with:
|
||||
nix_path: nixpkgs=channel:nixos-unstable
|
||||
- name: display nix version
|
||||
shell: bash
|
||||
run: nix --version
|
||||
- name: install alejandra
|
||||
shell: bash
|
||||
run: nix-env -i alejandra -f '<nixpkgs>'
|
||||
22
.github/actions/setup-python/action.yml
vendored
Normal file
22
.github/actions/setup-python/action.yml
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
name: setup python
|
||||
description: set up a python environment
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: install python
|
||||
uses: actions/setup-python@v5.1.1
|
||||
with:
|
||||
python-version: '3.12'
|
||||
- name: display python version
|
||||
shell: bash
|
||||
run: python -c 'import sys; print(sys.version)'
|
||||
- name: install poetry
|
||||
shell: bash
|
||||
run: python -m pip install --upgrade pip && pip install poetry yapf
|
||||
- name: cache poetry storage
|
||||
uses: actions/cache@v4.2.0
|
||||
with:
|
||||
path: ~/.cache/pypoetry
|
||||
key: ${{ runner.os }}-poetry-${{ hashFiles('**/pyproject.toml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-poetry-
|
||||
17
.github/actions/setup-racket/action.yml
vendored
Normal file
17
.github/actions/setup-racket/action.yml
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
name: setup racket
|
||||
description: set up a racket environment
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: install racket
|
||||
uses: Bogdanp/setup-racket@v1.11
|
||||
with:
|
||||
architecture: x64
|
||||
distribution: full
|
||||
version: stable
|
||||
- name: display racket version
|
||||
shell: bash
|
||||
run: racket --version
|
||||
- name: install raco fmt
|
||||
shell: bash
|
||||
run: raco pkg install --auto fmt
|
||||
22
.github/actions/setup-rust/action.yml
vendored
Normal file
22
.github/actions/setup-rust/action.yml
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
name: setup rust
|
||||
description: set up a rust environment
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: install rust
|
||||
uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||
with:
|
||||
components: rustfmt
|
||||
- name: display rust version
|
||||
shell: bash
|
||||
run: cargo --version
|
||||
- name: install cargo release
|
||||
shell: bash
|
||||
run: cargo install release
|
||||
- name: cache cargo registery
|
||||
uses: actions/cache@v4.2.0
|
||||
with:
|
||||
path: ~/.cargo
|
||||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cargo-
|
||||
76
.github/workflows/format-nix.yml
vendored
Normal file
76
.github/workflows/format-nix.yml
vendored
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
name: format
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
shell:
|
||||
description: the development shell to use for a dev environment
|
||||
required: true
|
||||
type: string
|
||||
language:
|
||||
description: the language to target for code formatting
|
||||
required: true
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
format:
|
||||
timeout-minutes: 15
|
||||
runs-on: [self-hosted, nix]
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- name: checkout code
|
||||
uses: actions/checkout@v4
|
||||
- name: activate nix shell
|
||||
uses: nicknovitski/nix-develop@v1.2.0
|
||||
with:
|
||||
arguments: "github:c4patino/nixos-config#${{ inputs.shell }}"
|
||||
- name: format all files
|
||||
run: |
|
||||
TARGET_DIR="${{ inputs.directory || '.' }}"
|
||||
|
||||
case "${{ inputs.language }}" in
|
||||
"csharp")
|
||||
(cd "$TARGET_DIR" && dotnet format)
|
||||
;;
|
||||
"go")
|
||||
(cd "$TARGET_DIR" && go fmt ./...)
|
||||
;;
|
||||
"js")
|
||||
prettier --write "$TARGET_DIR/*.{ts,tsx,js,jsx,mdx}" --cache,
|
||||
;;
|
||||
"lua")
|
||||
stylua "$TARGET_DIR"
|
||||
;;
|
||||
"nix")
|
||||
alejandra "$TARGET_DIR"
|
||||
;;
|
||||
"python")
|
||||
if find "$TARGET_DIR" -type f \( -name "*.py" \) | grep -q .; then
|
||||
yapf --in-place --parallel --recursive --exclude ".venv" "$TARGET_DIR"
|
||||
else
|
||||
echo "No Python files found in $TARGET_DIR. Skipping yapf."
|
||||
fi
|
||||
;;
|
||||
"racket")
|
||||
if find "$TARGET_DIR" -type f -name "*.rkt" | grep -q .; then
|
||||
find "$TARGET_DIR" -type f -name "*.rkt" -exec raco fmt -i {} \;
|
||||
else
|
||||
echo "No Racket files found in $TARGET_DIR. Skipping raco fmt."
|
||||
fi
|
||||
;;
|
||||
"rust")
|
||||
(cd "$TARGET_DIR" && cargo fmt --all)
|
||||
;;
|
||||
*)
|
||||
echo "unsupported language: ${{ inputs.language }}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
- name: commit changes
|
||||
uses: stefanzweifel/git-auto-commit-action@v5.0.1
|
||||
with:
|
||||
commit_message: |
|
||||
chore: autoformatting all ${{ inputs.language }} files
|
||||
|
||||
[skip ci]
|
||||
96
.github/workflows/format.yml
vendored
Normal file
96
.github/workflows/format.yml
vendored
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
name: format
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
language:
|
||||
description: the language to target for code formatting
|
||||
required: true
|
||||
type: string
|
||||
directory:
|
||||
description: "the directory to format (default: .)"
|
||||
required: false
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
format:
|
||||
timeout-minutes: 15
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- name: checkout code
|
||||
uses: actions/checkout@v4
|
||||
- name: set up csharp
|
||||
if: inputs.language == 'csharp'
|
||||
uses: c4patino/actions/.github/actions/setup-csharp@main
|
||||
- name: set up go
|
||||
if: inputs.language == 'go'
|
||||
uses: c4patino/actions/.github/actions/setup-go@main
|
||||
- name: set up javascript
|
||||
if: inputs.language == 'js'
|
||||
uses: c4patino/actions/.github/actions/setup-js@main
|
||||
- name: set up lua
|
||||
if: inputs.language == 'lua'
|
||||
uses: c4patino/actions/.github/actions/setup-lua@main
|
||||
- name: set up nix
|
||||
if: inputs.language == 'nix'
|
||||
uses: c4patino/actions/.github/actions/setup-nix@main
|
||||
- name: set up racket
|
||||
if: inputs.language == 'racket'
|
||||
uses: c4patino/actions/.github/actions/setup-racket@main
|
||||
- name: set up python
|
||||
if: inputs.language == 'python'
|
||||
uses: c4patino/actions/.github/actions/setup-python@main
|
||||
- name: set up rust
|
||||
if: inputs.language == 'rust'
|
||||
uses: c4patino/actions/.github/actions/setup-rust@main
|
||||
- name: format all files
|
||||
run: |
|
||||
TARGET_DIR="${{ inputs.directory || '.' }}"
|
||||
|
||||
case "${{ inputs.language }}" in
|
||||
"csharp")
|
||||
(cd "$TARGET_DIR" && dotnet format)
|
||||
;;
|
||||
"go")
|
||||
(cd "$TARGET_DIR" && go fmt ./...)
|
||||
;;
|
||||
"js")
|
||||
prettier --write "$TARGET_DIR/*.{ts,tsx,js,jsx,mdx}" --cache,
|
||||
;;
|
||||
"lua")
|
||||
stylua "$TARGET_DIR"
|
||||
;;
|
||||
"nix")
|
||||
alejandra "$TARGET_DIR"
|
||||
;;
|
||||
"python")
|
||||
if find "$TARGET_DIR" -type f \( -name "*.py" \) | grep -q .; then
|
||||
yapf --in-place --parallel --recursive --exclude ".venv" "$TARGET_DIR"
|
||||
else
|
||||
echo "No Python files found in $TARGET_DIR. Skipping yapf."
|
||||
fi
|
||||
;;
|
||||
"racket")
|
||||
if find "$TARGET_DIR" -type f -name "*.rkt" | grep -q .; then
|
||||
find "$TARGET_DIR" -type f -name "*.rkt" -exec raco fmt -i {} \;
|
||||
else
|
||||
echo "No Racket files found in $TARGET_DIR. Skipping raco fmt."
|
||||
fi
|
||||
;;
|
||||
"rust")
|
||||
(cd "$TARGET_DIR" && cargo fmt --all)
|
||||
;;
|
||||
*)
|
||||
echo "unsupported language: ${{ inputs.language }}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
- name: commit changes
|
||||
uses: stefanzweifel/git-auto-commit-action@v5.0.1
|
||||
with:
|
||||
commit_message: |
|
||||
chore: autoformatting all ${{ inputs.language }} files
|
||||
|
||||
[skip ci]
|
||||
74
.github/workflows/increment-nix.yml
vendored
Normal file
74
.github/workflows/increment-nix.yml
vendored
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
name: increment version
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
shell:
|
||||
description: the development shell to use for a dev environment
|
||||
required: true
|
||||
type: string
|
||||
language:
|
||||
description: the language to target for the version increment
|
||||
required: true
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
increment:
|
||||
timeout-minutes: 15
|
||||
runs-on: [self-hosted, nix]
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- name: checkout code
|
||||
uses: actions/checkout@v4
|
||||
- name: activate nix shell
|
||||
uses: nicknovitski/nix-develop@v1.2.0
|
||||
with:
|
||||
arguments: "github:c4patino/nixos-config#${{ inputs.shell }}"
|
||||
- name: determine pr merge or direct push
|
||||
id: pr-merge
|
||||
run: |
|
||||
if [[ "${{ github.event_name }}" == "push" && "${{ github.event.head_commit.message }}" == "Merge pull request"* ]]; then
|
||||
echo "pr_merge=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "pr_merge=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
- name: determine version bump type
|
||||
id: version-type
|
||||
run: |
|
||||
pr_merge="${{ steps.pr-merge.outputs.pr_merge }}"
|
||||
bump_type="patch"
|
||||
if [ "$pr_merge" == "true" ]; then
|
||||
tags="${{ steps.get_pr_tags.outputs.tags }}"
|
||||
if [[ "$tags" =~ "major" ]]; then bump_type="major"; fi
|
||||
if [[ "$tags" =~ "minor" ]]; then bump_type="minor"; fi
|
||||
fi
|
||||
echo "bump_type=$bump_type" >> $GITHUB_OUTPUT
|
||||
- name: bump package version
|
||||
id: version-bump
|
||||
run: |
|
||||
case "${{ inputs.language }}" in
|
||||
"python")
|
||||
poetry version ${{ steps.version-type.outputs.bump_type }}
|
||||
echo "version=$(poetry version -s)" >> $GITHUB_OUTPUT
|
||||
;;
|
||||
"rust")
|
||||
cargo release ${{ steps.version-type.outputs.bump_type }} --execute --no-confirm
|
||||
echo "version=$(cargo metadata --format-version 1 | jq -r '.packages[0].version')" >> $GITHUB_OUTPUT
|
||||
;;
|
||||
"js")
|
||||
pnpm version ${{ steps.version-type.outputs.bump_type }} --no-commit-hooks --no-git-tag-version
|
||||
echo "version=$(jq -r .version < package.json)" >> $GITHUB_OUTPUT
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported language: ${{ inputs.language }}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
- name: commit changes
|
||||
uses: stefanzweifel/git-auto-commit-action@v5.0.1
|
||||
with:
|
||||
commit_message: |
|
||||
chore: incrementing version to ${{ steps.version-bump.outputs.version }}
|
||||
|
||||
[skip ci]
|
||||
75
.github/workflows/increment.yml
vendored
Normal file
75
.github/workflows/increment.yml
vendored
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
name: increment version
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
language:
|
||||
description: the language to target for the version increment
|
||||
required: true
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
increment:
|
||||
timeout-minutes: 15
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- name: checkout code
|
||||
uses: actions/checkout@v4
|
||||
- name: set up js
|
||||
if: inputs.language == 'js'
|
||||
uses: c4patino/actions/.github/actions/setup-js@main
|
||||
- name: set up python
|
||||
if: inputs.language == 'python'
|
||||
uses: c4patino/actions/.github/actions/setup-python@main
|
||||
- name: set up rust
|
||||
if: inputs.language == 'rust'
|
||||
uses: c4patino/actions/.github/actions/setup-rust@main
|
||||
- name: determine pr merge or direct push
|
||||
id: pr-merge
|
||||
run: |
|
||||
if [[ "${{ github.event_name }}" == "push" && "${{ github.event.head_commit.message }}" == "Merge pull request"* ]]; then
|
||||
echo "pr_merge=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "pr_merge=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
- name: determine version bump type
|
||||
id: version-type
|
||||
run: |
|
||||
pr_merge="${{ steps.pr-merge.outputs.pr_merge }}"
|
||||
bump_type="patch"
|
||||
if [ "$pr_merge" == "true" ]; then
|
||||
tags="${{ steps.get_pr_tags.outputs.tags }}"
|
||||
if [[ "$tags" =~ "major" ]]; then bump_type="major"; fi
|
||||
if [[ "$tags" =~ "minor" ]]; then bump_type="minor"; fi
|
||||
fi
|
||||
echo "bump_type=$bump_type" >> $GITHUB_OUTPUT
|
||||
- name: bump package version
|
||||
id: version-bump
|
||||
run: |
|
||||
case "${{ inputs.language }}" in
|
||||
"python")
|
||||
poetry version ${{ steps.version-type.outputs.bump_type }}
|
||||
echo "version=$(poetry version -s)" >> $GITHUB_OUTPUT
|
||||
;;
|
||||
"rust")
|
||||
cargo release ${{ steps.version-type.outputs.bump_type }} --execute --no-confirm
|
||||
echo "version=$(cargo metadata --format-version 1 | jq -r '.packages[0].version')" >> $GITHUB_OUTPUT
|
||||
;;
|
||||
"js")
|
||||
pnpm version ${{ steps.version-type.outputs.bump_type }} --no-commit-hooks --no-git-tag-version
|
||||
echo "version=$(jq -r .version < package.json)" >> $GITHUB_OUTPUT
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported language: ${{ inputs.language }}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
- name: commit changes
|
||||
uses: stefanzweifel/git-auto-commit-action@v5.0.1
|
||||
with:
|
||||
commit_message: |
|
||||
chore: incrementing version to ${{ steps.version-bump.outputs.version }}
|
||||
|
||||
[skip ci]
|
||||
Loading…
Add table
Add a link
Reference in a new issue