From 0e64439dbaa8df6ce2d8c1b01ab83a92e09f1cf6 Mon Sep 17 00:00:00 2001 From: Majo Richter <39386799+NobleMajo@users.noreply.github.com> Date: Sun, 8 Dec 2024 17:34:10 +0100 Subject: [PATCH] Create pull-request.yml --- .github/workflows/pull-request.yml | 66 ++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/pull-request.yml diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 0000000..2ed56da --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,66 @@ +name: Build and Test on Pull Request + +on: + pull_request: + branches: + - main + +jobs: + build-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' + + - name: Install dependencies + id: deps + run: npm ci + continue-on-error: true + + - name: Build project + id: build + run: npm run build + continue-on-error: true + + - name: Run tests + id: test + run: npm run test + continue-on-error: true + + - name: Post comment on PR + uses: peter-evans/create-or-update-comment@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + repository: ${{ github.repository }} + issue-number: ${{ github.event.pull_request.number }} + body: | + ${{ steps.outcome.outputs.message }} + + - id: outcome + run: | + status() { + if [ "$1" == "success" ]; then + echo "✅ Success" + else + echo "❌ Failed" + fi + } + + deps_status=$(status "${{ steps.deps.outcome }}") + build_status=$(status "${{ steps.build.outcome }}") + test_status=$(status "${{ steps.test.outcome }}") + + if [ "${{ steps.deps.outcome }}" == "success" ] && \ + [ "${{ steps.build.outcome }}" == "success" ] && \ + [ "${{ steps.test.outcome }}" == "success" ]; then + echo "message=✅ Everything successful! Deps, build and tests passed!" >> $GITHUB_ENV + else + echo "message=❌ Failed tests! Your changes may have broken something:\n- install dependencies: $deps_status\n- build project: $build_status\n- run tests: $test_status\n\nPlease run the test locally and review and fix your changes." >> $GITHUB_ENV + fi + shell: bash