diff --git a/.github/ci/final-check.sh b/.github/ci/final-check.sh new file mode 100644 index 0000000..27e90d0 --- /dev/null +++ b/.github/ci/final-check.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# Exit immediately if a command exits with a non-zero status. +set -e +# Enable the globstar shell option +shopt -s globstar +# Make sure we are inside the github workspace +cd $GITHUB_WORKSPACE +echo $STEPS_CONTEXT +step=$1 +status=$2 +export BODYMESSAGE="$(git log -1 $GITHUB_SHA --pretty=oneline --abbrev-commit)" +export BACKTICK='`'; +export TIMESTAMP=$(date --utc +%FT%TZ); +export GITHUB_ACTOR_NAME="$(git log -1 $GITHUB_SHA --pretty="%aN")"; +export COMMIT_FORMATTED="[$BACKTICK${GITHUB_SHA:0:7}$BACKTICK](https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA)"; + +if [[ "$status" == "success" ]]; +then + echo "Success build" + if [ -z "$DISCORD_WEBHOOK_URL" ]; + then + echo "no need bot" + else + curl -v -H User-Agent:bot -H Content-Type:application/json -d '{"avatar_url":"https://pngimg.com/uploads/github/github_PNG90.png","username":"github-action","embeds":[{"author":{"name":"Build #'"$step"' Passed - '"$GITHUB_ACTOR_NAME"'","url":"https://github.com/'"$GITHUB_REPOSITORY"'/actions/runs/'"$GITHUB_RUN_ID"'"},"url":"https://github.com/'"$GITHUB_REPOSITORY"'/actions/runs/'"$GITHUB_RUN_ID"'","title":"['"$GITHUB_REPOSITORY"':job#'"$GITHUB_RUN_NUMBER"'] ","color":65280,"fields":[{"name":"_ _", "value": "'"$COMMIT_FORMATTED"' - '"$BODYMESSAGE"'"}],"timestamp":"'"$TIMESTAMP"'","footer":{"text":"ESP3D CI"}}]}' $DISCORD_WEBHOOK_URL; + fi +else + echo "Build failed" + if [ -z "$DISCORD_WEBHOOK_URL" ]; + then + echo "no need bot" + else + curl -v -H User-Agent:bot -H Content-Type:application/json -d '{"avatar_url":"https://pngimg.com/uploads/github/github_PNG90.png","username":"github-action","embeds":[{"author":{"name":"Build #'"$step"' Failed - '"$GITHUB_ACTOR_NAME"'","url":"https://github.com/'"$GITHUB_REPOSITORY"'/actions/runs/'"$GITHUB_RUN_ID"'"},"url":"https://github.com/'"$GITHUB_REPOSITORY"'/actions/runs/'"$GITHUB_RUN_ID"'","title":"['"$GITHUB_REPOSITORY"':job#'"$GITHUB_RUN_NUMBER"'] ","color":16711680,"fields":[{"name":"_ _", "value": "'"$COMMIT_FORMATTED"' - '"$BODYMESSAGE"'"}],"timestamp":"'"$TIMESTAMP"'","footer":{"text":"ESP3D CI"}}]}' $DISCORD_WEBHOOK_URL; + fi + exit 1 +fi + + diff --git a/.github/ci/install-platformio.sh b/.github/ci/install-platformio.sh new file mode 100644 index 0000000..a54fdc0 --- /dev/null +++ b/.github/ci/install-platformio.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# Exit immediately if a command exits with a non-zero status. +set -e +# Enable the globstar shell option +shopt -s globstar + +pip install -U platformio +platformio update + diff --git a/.github/workflows/build-ci.yml b/.github/workflows/build-ci.yml new file mode 100644 index 0000000..e81023b --- /dev/null +++ b/.github/workflows/build-ci.yml @@ -0,0 +1,32 @@ +name: build-ci + +on: [pull_request, push] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: '16.x' + - name: Install libraries + id: setuptools + run: npm install + continue-on-error: true + - name: Build all files + id: buildall + run: npm run buildall + continue-on-error: true + - name: Failure check + env: + STEPS_CONTEXT: ${{ toJson(steps) }} + DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} + if: steps.setuptools.outcome == 'failure' || steps.buildall.outcome == 'failure' + run: bash ./.github/ci/final-check.sh "$GITHUB_RUN_ID" "failure" + - name: Success check + env: + DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} + if: steps.setuptools.outcome == 'success' && steps.buildall.outcome == 'success' + run: bash ./.github/ci/final-check.sh "$GITHUB_RUN_ID" "success"