diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 27c10a5..af2c959 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,9 +4,15 @@ on: push: branches: - master + paths-ignore: + - 'license' + - '**.md' pull_request: branches: - master + paths-ignore: + - 'license' + - '**.md' types: - opened - reopened @@ -14,28 +20,9 @@ on: jobs: - build: - name: Build - runs-on: ubuntu-18.04 - steps: - - name: Checkout Repository - uses: actions/checkout@v2 - - name: Build action - run: make build.docker VERSION=${{ github.sha }} - test: - name: Test-Script - runs-on: ubuntu-18.04 - steps: - - name: Checkout Repository - uses: actions/checkout@v2 - - name: Test Script - run: make test.shell - - test-action: name: Test-Action runs-on: ubuntu-18.04 - needs: [build, test] continue-on-error: true steps: - name: Checkout Repository diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index faf239d..0000000 --- a/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM alpine:3.12 - -LABEL maintainer="David Boenig " -LABEL repository="https://github.com/martialonline/workflow-status" - -RUN apk add --no-cache curl jq - -COPY entrypoint.sh /entrypoint.sh - -ENTRYPOINT [ "/entrypoint.sh" ] \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index 853f490..0000000 --- a/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -VERSION ?= latest -TAG ?= $(VERSION) -PREFIX ?= workflow-status - -GIT_COMMIT = $(shell git rev-parse --short HEAD) - -export DOCKER_BUILDKIT = 1 - -test: test.shell - -test.shell: - shellcheck entrypoint.sh - -build.docker: - docker build -t $(PREFIX):$(TAG) . - -clean: - docker stop ${PREFIX}:${TAG} || true - docker rmi -f ${PREFIX}:${TAG} || true - docker rmi -f $(docker images -q -f dangling=true) || true \ No newline at end of file diff --git a/README.md b/README.md index 57b73f1..f0835d3 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Simply add a job to the end of your workflow and list the last job as dependency needs: [build] if: always() steps: - - uses: martialonline/workflow-status@v1 + - uses: martialonline/workflow-status@v2 id: check - run: echo "Workflow failed" if: steps.check.outputs.status == 'failure' @@ -67,7 +67,7 @@ jobs: needs: [build] if: always() steps: - - uses: martialonline/workflow-status@v1 + - uses: martialonline/workflow-status@v2 id: check - uses: 8398a7/action-slack@v3 with: diff --git a/action.yml b/action.yml index 7ffd6b5..9c97f8a 100644 --- a/action.yml +++ b/action.yml @@ -1,15 +1,38 @@ -name: 'Workflow Status Action' -description: 'Trigger events like notifications or alerts using the workflow status' -author: 'David Boenig ' +name: "Workflow Status Action" +description: "Trigger events like notifications or alerts using the workflow status" +author: "David Boenig " outputs: status: - description: 'Returns either success or failed as workflow status' + description: "Returns either success or failed as workflow status" + value: ${{ steps.workflow-status.outputs.status }} runs: - using: 'docker' - image: 'Dockerfile' - env: - DOCKER_BUILDKIT: '1' + using: "composite" + steps: + - id: workflow-status + run: | + url="${GITHUB_API_URL}/repos" + repo="${GITHUB_REPOSITORY}" + run_id="${GITHUB_RUN_ID}" + + failure=$(curl -s "${url}/${repo}/actions/runs/${run_id}/jobs" | \ + jq -r '.jobs[] | select(.status == "completed" and .conclusion == "failure").conclusion' | \ + wc -l) + + cancelled=$(curl -s "${url}/${repo}/actions/runs/${run_id}/jobs" | \ + jq -r '.jobs[] | select(.status == "completed" and .conclusion == "cancelled").conclusion' | \ + wc -l) + + if [ "${failure}" -gt 0 ]; then + status="failure" + elif [ "${cancelled}" -gt 0 ]; then + status="cancelled" + else + status="success" + fi + + echo "::set-output name=status::${status}" + shell: bash branding: icon: check-square color: gray-dark \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100755 index 02f9123..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -set -euf - -url="${GITHUB_API_URL}/repos" -repo="${GITHUB_REPOSITORY}" -run_id="${GITHUB_RUN_ID}" - -failure=$(curl -s "${url}/${repo}/actions/runs/${run_id}/jobs" | \ -jq -r '.jobs[] | select(.status == "completed" and .conclusion == "failure").conclusion' | \ -wc -l) - -cancelled=$(curl -s "${url}/${repo}/actions/runs/${run_id}/jobs" | \ -jq -r '.jobs[] | select(.status == "completed" and .conclusion == "cancelled").conclusion' | \ -wc -l) - -if [ "${failure}" -gt 0 ]; then - status="failure" -elif [ "${cancelled}" -gt 0 ]; then - status="cancelled" -else - status="success" -fi - -echo "::set-output name=status::${status}"