From abea078a673316c1592d28ba56982f48146ab0d2 Mon Sep 17 00:00:00 2001 From: guzhongren Date: Sat, 22 Jan 2022 15:12:31 +0800 Subject: [PATCH 1/3] Create main.yml --- .github/workflows/main.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..30a4bc1 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,36 @@ +# This is a basic workflow to help you get started with Actions + +name: CI + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the main branch + push: + branches: [ main ] + pull_request: + branches: [ main ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + # Runs a single command using the runners shell + - name: Run a one-line script + run: echo Hello, world! + + # Runs a set of commands using the runners shell + - name: Run a multi-line script + run: | + echo Add other actions to build, + echo test, and deploy your project. From e19896e3a05c864c27c5c251146c96bc47e083f2 Mon Sep 17 00:00:00 2001 From: guzhongren Date: Sat, 22 Jan 2022 15:24:50 +0800 Subject: [PATCH 2/3] feat(shellcheck): add shell check for shell and pipeline --- .github/workflows/main.yml | 10 ++-------- docker-compose.yaml | 8 ++++++++ validate.sh | 11 +++++++++++ 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 docker-compose.yaml create mode 100755 validate.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 30a4bc1..c0ed349 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,11 +26,5 @@ jobs: - uses: actions/checkout@v2 # Runs a single command using the runners shell - - name: Run a one-line script - run: echo Hello, world! - - # Runs a set of commands using the runners shell - - name: Run a multi-line script - run: | - echo Add other actions to build, - echo test, and deploy your project. + - name: shell check + run: docker-compose run --rm shellcheck ./validate.sh diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..4349a5a --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,8 @@ +--- +version: '3.9' +services: + shellcheck: + image: koalaman/shellcheck-alpine:latest + volumes: + - ".:/build" + working_dir: /build diff --git a/validate.sh b/validate.sh new file mode 100755 index 0000000..c732d71 --- /dev/null +++ b/validate.sh @@ -0,0 +1,11 @@ +#!/bin/sh -l + +set -euo pipefile + +rc=0 +for filename in $(find ./* -name '*.sh'); do + echo "Validating" + shellcheck "${filename}" || exit $? +done + +exit $? \ No newline at end of file From 48f3917716df970b7b335941a5a4818e1dbbb7fa Mon Sep 17 00:00:00 2001 From: guzhongren Date: Sat, 22 Jan 2022 15:51:14 +0800 Subject: [PATCH 3/3] fix(issue): fix shell issue which ware found by shellcheck --- entrypoint.sh | 4 ++-- validate.sh | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 62b60d3..e6d574c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,10 +1,10 @@ -#!/bin/sh -l +#!/bin/sh +# shellcheck disable=SC3060 set -e # if a command fails it stops the execution set -u # script fails if trying to access to an undefined variable echo "[+] Action start" -SOURCE_BEFORE_DIRECTORY="${1}" SOURCE_DIRECTORY="${2}" DESTINATION_GITHUB_USERNAME="${3}" DESTINATION_REPOSITORY_NAME="${4}" diff --git a/validate.sh b/validate.sh index c732d71..0536b4c 100755 --- a/validate.sh +++ b/validate.sh @@ -1,11 +1,13 @@ -#!/bin/sh -l +#!/bin/sh +# shellcheck disable=SC2044 -set -euo pipefile +set -eu pipefile rc=0 for filename in $(find ./* -name '*.sh'); do - echo "Validating" + echo "Start to validating ${filename}" shellcheck "${filename}" || exit $? + echo "🚀Successfully Validated ${filename}" done -exit $? \ No newline at end of file +exit $rc \ No newline at end of file