Skip to content

Add template workflow to check general file formatting #8

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

Merged
merged 1 commit into from
Jun 15, 2021
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
3 changes: 3 additions & 0 deletions .ecrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Exclude": ["LICENSE.txt"]
}
57 changes: 57 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/master/workflow-templates/assets/shared/.editorconfig
# See: https://editorconfig.org/
# The formatting style defined in this file is the official standardized style to be used in all Arduino Tooling
# projects and should not be modified.
# Note: indent style for each file type is defined even when it matches the universal config in order to make it clear
# that this type has an official style.

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.{adoc,asc,asciidoc}]
indent_size = 2
indent_style = space

[*.{bash,sh}]
indent_size = 2
indent_style = space

[*.{c,cc,cp,cpp,cxx,h,hh,hpp,hxx,ii,inl,ino,ixx,pde,tpl,tpp,txx}]
indent_size = 2
indent_style = space

[*.go]
indent_style = tab

[*.java]
indent_size = 2
indent_style = space

[*.{js,jsx,json,jsonc,json5,ts,tsx}]
indent_size = 2
indent_style = space

[*.{md,mdx,mkdn,mdown,markdown}]
indent_size = unset
indent_style = space

[*.proto]
indent_size = 2
indent_style = space

[*.py]
indent_size = 4
indent_style = space

[*.svg]
indent_size = 2
indent_style = space

[*.{yaml,yml}]
indent_size = 2
indent_style = space
47 changes: 47 additions & 0 deletions .github/workflows/check-ci-sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This repository contains intentionally duplicated copies of template workflows under .github/workflows used for this
# repository's own CI system.
#
# This workflow checks that the copies are in sync.
# If the workflow fails, run `task fix` and commit.

name: Check CI Workflows Sync

# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
on:
push:
paths:
- ".github/workflows/*.ya?ml"
- "Taskfile.ya?ml"
- "workflow-templates/*.ya?ml"
pull_request:
paths:
- ".github/workflows/*.ya?ml"
- "Taskfile.ya?ml"
- "workflow-templates/*.ya?ml"
workflow_dispatch:
repository_dispatch:

jobs:
check-sync:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Sync files
run: task --silent ci:sync

- name: Check file duplicates sync
run: |
git add .
if ! git diff --color --exit-code HEAD; then
echo "::error::File duplicates are out of sync. Please run \"task fix\""
exit 1
fi
39 changes: 39 additions & 0 deletions .github/workflows/check-config-sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This repository contains intentionally duplicated copies of template configuration files in use for this repository's
# own purposes
#
# This workflow checks that the copies are in sync.
# If the workflow fails, run `task fix` and commit.

name: Check Configuration Files Sync

# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
on:
push:
pull_request:
workflow_dispatch:
repository_dispatch:

jobs:
check-sync:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Sync files
run: task --silent config:sync

- name: Check file duplicates sync
run: |
git add .
if ! git diff --color --exit-code HEAD; then
echo "::error::File duplicates are out of sync. Please run \"task fix\""
exit 1
fi
65 changes: 65 additions & 0 deletions .github/workflows/check-general-formatting-task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/master/workflow-templates/check-general-formatting-task.md
name: Check General Formatting

# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
on:
push:
pull_request:
schedule:
# Run every Tuesday at 8 AM UTC to catch breakage caused by changes to tools.
- cron: "0 8 * * TUE"
workflow_dispatch:
repository_dispatch:

jobs:
check:
runs-on: ubuntu-latest

steps:
- name: Set environment variables
run: |
# See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
echo "EC_INSTALL_PATH=${{ runner.temp }}/editorconfig-checker" >> "$GITHUB_ENV"

- name: Checkout repository
uses: actions/checkout@v2

- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Get data for latest editorconfig-checker release
id: get-release-data
uses: octokit/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# Pre-releases are ignored
route: GET /repos/:owner/:repo/releases/latest
# The following inputs result in "Unexpected input" warnings on the workflow run log and summary page,
# but they are correct
owner: editorconfig-checker
repo: editorconfig-checker

- name: Download release binary
id: download-release
uses: carlosperate/[email protected]
with:
# See: https://github.com/editorconfig-checker/editorconfig-checker/releases
file-url: https://github.com/editorconfig-checker/editorconfig-checker/releases/download/${{ fromJson(steps.get-release-data.outputs.data).tag_name }}/ec-linux-amd64.tar.gz
location: ${{ env.EC_INSTALL_PATH }}

- name: Install editorconfig-checker
run: |
cd "${{ env.EC_INSTALL_PATH }}"
tar --extract --file="${{ steps.download-release.outputs.file-path }}"
# Give the binary a standard name
mv "${{ env.EC_INSTALL_PATH }}/bin/ec-linux-amd64" "${{ env.EC_INSTALL_PATH }}/bin/ec"
# Add installation to PATH:
# See: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#adding-a-system-path
echo "${{ env.EC_INSTALL_PATH }}/bin" >> "$GITHUB_PATH"

- name: Check formatting
run: task --silent general:check-formatting
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Tooling Project Assets

[![Check Configuration Files status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-configuration-files.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-configuration-files.yml)
[![Check General Formatting status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-general-formatting-task.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-general-formatting-task.yml)
[![Check License status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-license.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-license.yml)
[![Check Workflow Duplicates Sync status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-dependabot-sync.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-dependabot-sync.yml)
[![Check CI Workflows Sync status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-ci-sync.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-ci-sync.yml)
[![Check Configuration Files Sync status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-config-sync.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-config-sync.yml)

The [Arduino](https://www.arduino.cc/) Tooling Team's collection of reusable project infrastructure assets.

Expand Down
35 changes: 35 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,48 @@ tasks:
fix:
desc: Make automated corrections to the project's files
deps:
- task: ci:sync
- task: config:sync
- task: dependabot:sync

check:
desc: Check for problems with the project
deps:
- task: general:check-formatting
- task: config:validate

general:check-formatting:
desc: Check basic formatting style of all files
cmds:
- |
if ! which ec &>/dev/null; then
echo "ec not found or not in PATH. Please install: https://github.com/editorconfig-checker/editorconfig-checker#installation"
exit 1
fi
- ec

ci:sync:
desc: Sync CI workflows from templates
vars:
WORKFLOWS_PATH: "./.github/workflows"
WORKFLOW_TEMPLATES_PATH: "./workflow-templates"
cmds:
- |
cp \
"{{.WORKFLOW_TEMPLATES_PATH}}/check-general-formatting-task.yml" \
"{{.WORKFLOWS_PATH}}"

config:sync:
desc: Sync configuration files from templates
vars:
REPOSITORY_ROOT_PATH: "./"
WORKFLOW_TEMPLATE_ASSETS_PATH: "./workflow-templates/assets"
cmds:
- |
cp \
"{{.WORKFLOW_TEMPLATE_ASSETS_PATH}}/shared/.editorconfig" \
"{{.REPOSITORY_ROOT_PATH}}"

dependabot:sync:
desc: Sync workflow duplicates for dependabot checks
vars:
Expand Down
3 changes: 3 additions & 0 deletions workflow-templates/assets/check-general-formatting-task/.ecrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Exclude": ["LICENSE.txt"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/master/workflow-templates/assets/check-general-formatting-task/Taskfile.yml
# See: https://taskfile.dev/#/usage
version: "3"

tasks:
general:check-formatting:
desc: Check basic formatting style of all files
cmds:
- |
if ! which ec &>/dev/null; then
echo "ec not found or not in PATH. Please install: https://github.com/editorconfig-checker/editorconfig-checker#installation"
exit 1
fi
- ec
57 changes: 57 additions & 0 deletions workflow-templates/assets/shared/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/master/workflow-templates/assets/shared/.editorconfig
# See: https://editorconfig.org/
# The formatting style defined in this file is the official standardized style to be used in all Arduino Tooling
# projects and should not be modified.
# Note: indent style for each file type is defined even when it matches the universal config in order to make it clear
# that this type has an official style.

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.{adoc,asc,asciidoc}]
indent_size = 2
indent_style = space

[*.{bash,sh}]
indent_size = 2
indent_style = space

[*.{c,cc,cp,cpp,cxx,h,hh,hpp,hxx,ii,inl,ino,ixx,pde,tpl,tpp,txx}]
indent_size = 2
indent_style = space

[*.go]
indent_style = tab

[*.java]
indent_size = 2
indent_style = space

[*.{js,jsx,json,jsonc,json5,ts,tsx}]
indent_size = 2
indent_style = space

[*.{md,mdx,mkdn,mdown,markdown}]
indent_size = unset
indent_style = space

[*.proto]
indent_size = 2
indent_style = space

[*.py]
indent_size = 4
indent_style = space

[*.svg]
indent_size = 2
indent_style = space

[*.{yaml,yml}]
indent_size = 2
indent_style = space
Loading