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

Apply update of workflows from asset repo #75

Merged
merged 2 commits into from
Apr 16, 2024
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
19 changes: 18 additions & 1 deletion .github/workflows/check-go-dependencies-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ on:
jobs:
run-determination:
runs-on: ubuntu-latest
permissions: {}
outputs:
result: ${{ steps.determination.outputs.result }}
steps:
Expand All @@ -56,19 +57,27 @@ jobs:
RESULT="false"
fi

echo "::set-output name=result::$RESULT"
echo "result=$RESULT" >> $GITHUB_OUTPUT

check-cache:
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

# This is required to allow jonabc/setup-licensed to install licensed via Ruby gem.
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ruby # Install latest version

- name: Install licensed
uses: jonabc/setup-licensed@v1
with:
Expand Down Expand Up @@ -112,13 +121,21 @@ jobs:
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

# This is required to allow jonabc/setup-licensed to install licensed via Ruby gem.
- name: Install Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ruby # Install latest version

- name: Install licensed
uses: jonabc/setup-licensed@v1
with:
Expand Down
104 changes: 79 additions & 25 deletions .github/workflows/check-go-task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,67 @@ env:
# See: https://github.com/actions/setup-go/tree/main#supported-version-syntax
GO_VERSION: "1.19"

# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
on:
create:
push:
paths:
- ".github/workflows/check-go-task.ya?ml"
- "Taskfile.ya?ml"
- "go.mod"
- "go.sum"
- ".golangci.ya?ml"
- "**/go.mod"
- "**/go.sum"
- "**.go"
pull_request:
paths:
- ".github/workflows/check-go-task.ya?ml"
- "Taskfile.ya?ml"
- "go.mod"
- "go.sum"
- ".golangci.ya?ml"
- "**/go.mod"
- "**/go.sum"
- "**.go"
workflow_dispatch:
repository_dispatch:

jobs:
check-errors:
run-determination:
runs-on: ubuntu-latest

permissions: {}
outputs:
result: ${{ steps.determination.outputs.result }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

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

- name: Check for errors
run: task go:vet
- name: Determine if the rest of the workflow should run
id: determination
run: |
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
if [[
"${{ github.event_name }}" != "create" ||
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
]]; then
# Run the other jobs.
RESULT="true"
else
# There is no need to run the other jobs.
RESULT="false"
fi

echo "result=$RESULT" >> $GITHUB_OUTPUT

check-outdated:
name: check-outdated (${{ matrix.module.path }})
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest
permissions:
contents: read

strategy:
fail-fast: false

matrix:
module:
- path: ./

steps:
- name: Checkout repository
Expand All @@ -65,13 +83,27 @@ jobs:
version: 3.x

- name: Modernize usages of outdated APIs
env:
GO_MODULE_PATH: ${{ matrix.module.path }}
run: task go:fix

- name: Check if any fixes were needed
run: git diff --color --exit-code

check-style:
name: check-style (${{ matrix.module.path }})
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest
permissions:
contents: read

strategy:
fail-fast: false

matrix:
module:
- path: ./

steps:
- name: Checkout repository
Expand All @@ -88,14 +120,30 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Install golint
run: go install golang.org/x/lint/golint@latest
- name: Install golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54

- name: Check style
env:
GO_MODULE_PATH: ${{ matrix.module.path }}
run: task --silent go:lint

check-formatting:
name: check-formatting (${{ matrix.module.path }})
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest
permissions:
contents: read

strategy:
fail-fast: false

matrix:
module:
- path: ./

steps:
- name: Checkout repository
Expand All @@ -113,14 +161,20 @@ jobs:
version: 3.x

- name: Format code
env:
GO_MODULE_PATH: ${{ matrix.module.path }}
run: task go:format

- name: Check formatting
run: git diff --color --exit-code

check-config:
name: check-config (${{ matrix.module.path }})
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest
permissions:
contents: read

strategy:
fail-fast: false
Expand Down
69 changes: 56 additions & 13 deletions .github/workflows/check-license.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-license.md
name: Check License

env:
# TODO: Define the project's license file name here:
EXPECTED_LICENSE_FILENAME: LICENSE.txt
# SPDX identifier: https://spdx.org/licenses/
# TODO: Define the project's license type here
EXPECTED_LICENSE_TYPE: GPL-3.0

# See: https://docs.github.com/en/actions/reference/events-that-trigger-workflows
# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
on:
create:
push:
paths:
- ".github/workflows/check-license.ya?ml"
Expand All @@ -31,8 +25,50 @@ on:
repository_dispatch:

jobs:
run-determination:
runs-on: ubuntu-latest
permissions: {}
outputs:
result: ${{ steps.determination.outputs.result }}
steps:
- name: Determine if the rest of the workflow should run
id: determination
run: |
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
if [[
"${{ github.event_name }}" != "create" ||
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
]]; then
# Run the other jobs.
RESULT="true"
else
# There is no need to run the other jobs.
RESULT="false"
fi

echo "result=$RESULT" >> $GITHUB_OUTPUT

check-license:
name: ${{ matrix.check-license.path }}
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest
permissions:
contents: read

strategy:
fail-fast: false

matrix:
check-license:
# TODO: Add additional paths where license files should be
- path: ./
# TODO: Define the project's license file name here:
expected-filename: LICENSE.txt
# SPDX identifier: https://spdx.org/licenses/
# TODO: Define the project's license type here
expected-type: GPL-3.0

steps:
- name: Checkout repository
Expand All @@ -46,21 +82,28 @@ jobs:
- name: Install licensee
run: gem install licensee

- name: Check license file
- name: Check license file for ${{ matrix.check-license.path }}
run: |
EXIT_STATUS=0

# Go into folder path
cd ./${{ matrix.check-license.path }}

# See: https://github.com/licensee/licensee
LICENSEE_OUTPUT="$(licensee detect --json --confidence=100)"

DETECTED_LICENSE_FILE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].filename | tr --delete '\r')"
echo "Detected license file: $DETECTED_LICENSE_FILE"
if [ "$DETECTED_LICENSE_FILE" != "\"${EXPECTED_LICENSE_FILENAME}\"" ]; then
echo "::error file=${DETECTED_LICENSE_FILE}::detected license file $DETECTED_LICENSE_FILE doesn't match expected: $EXPECTED_LICENSE_FILENAME"
if [ "$DETECTED_LICENSE_FILE" != "\"${{ matrix.check-license.expected-filename }}\"" ]; then
echo "::error file=${DETECTED_LICENSE_FILE}::detected license file $DETECTED_LICENSE_FILE doesn't match expected: ${{ matrix.check-license.expected-filename }}"
EXIT_STATUS=1
fi

DETECTED_LICENSE_TYPE="$(echo "$LICENSEE_OUTPUT" | jq .matched_files[0].matched_license | tr --delete '\r')"
echo "Detected license type: $DETECTED_LICENSE_TYPE"
if [ "$DETECTED_LICENSE_TYPE" != "\"${EXPECTED_LICENSE_TYPE}\"" ]; then
echo "::error file=${DETECTED_LICENSE_FILE}::detected license type $DETECTED_LICENSE_TYPE doesn't match expected \"${EXPECTED_LICENSE_TYPE}\""
if [ "$DETECTED_LICENSE_TYPE" != "\"${{ matrix.check-license.expected-type }}\"" ]; then
echo "::error file=${DETECTED_LICENSE_FILE}::detected license type $DETECTED_LICENSE_TYPE doesn't match expected \"${{ matrix.check-license.expected-type }}\""
EXIT_STATUS=1
fi

exit $EXIT_STATUS
Loading
Loading