diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4214694..1b94d95 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,11 +10,14 @@ jobs: # unit tests units: runs-on: ubuntu-latest + env: + # ncc@0.28.6 uses legacy OpenSSL hashing; Node 20+ requires this flag + NODE_OPTIONS: --openssl-legacy-provider steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v4 with: - node-version: 16 + node-version: 20 - run: npm ci - run: npm test diff --git a/action.yml b/action.yml index 4803a6b..86a9914 100644 --- a/action.yml +++ b/action.yml @@ -17,7 +17,7 @@ inputs: description: "If set, always create SSH debug sessions even on success." required: false runs: - using: 'node16' + using: 'node20' main: 'dist/index.js' pre: 'dist/setup.js' post: 'dist/cleanup.js' diff --git a/common/branch-info/action.yml b/common/branch-info/action.yml new file mode 100644 index 0000000..cff7832 --- /dev/null +++ b/common/branch-info/action.yml @@ -0,0 +1,29 @@ +name: "Branch Info" +description: "Extracts branch name and short SHA from the GitHub context. Reusable across all actions." + +outputs: + branch: + description: "The branch name (handles both push and pull_request events)" + value: ${{ steps.set-branch.outputs.branch }} + short_sha: + description: "The first 7 characters of the commit SHA" + value: ${{ steps.get-short-sha.outputs.short_sha }} + +runs: + using: "composite" + steps: + - name: Set branch variable + id: set-branch + shell: bash + run: | + if [ "${{ github.event_name }}" == "pull_request" ]; then + branch="${{ github.event.pull_request.head.ref }}" + else + branch="${{ github.ref }}" + branch="${branch#refs/heads/}" + fi + echo "branch=${branch}" >> $GITHUB_OUTPUT + - name: Get short sha + id: get-short-sha + shell: bash + run: echo "short_sha=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT diff --git a/deploy/eks/action.yml b/deploy/eks/action.yml index ef1404c..f9dee48 100644 --- a/deploy/eks/action.yml +++ b/deploy/eks/action.yml @@ -40,21 +40,9 @@ inputs: runs: using: "composite" steps: - - name: Set branch variable - id: set-branch - shell: bash - run: | - if [ "${{ github.event_name }}" == "pull_request" ]; then - branch="${{ github.event.pull_request.head.ref }}" - else - branch="${{ github.ref }}" - branch="${branch#refs/heads/}" - fi - echo "branch=${branch}" >> $GITHUB_OUTPUT - - name: Get short sha - id: get-short-sha - run: echo "short_sha=`echo ${GITHUB_SHA::7}`" >> $GITHUB_OUTPUT - shell: bash + - name: Get branch and commit info + id: branch-info + uses: wishabi/github-actions/common/branch-info@v0 - name: Validate AWS credentials input shell: bash run: | @@ -100,15 +88,15 @@ runs: # Execute command eval $cmd - name: Notify slack channel on success - if: success() && inputs.SLACK_SUCCESS_CHANNEL_ID != null - uses: slackapi/slack-github-action@v1.24.0 + if: success() && inputs.SLACK_SUCCESS_CHANNEL_ID != '' + uses: slackapi/slack-github-action@v1.27.1 env: SLACK_BOT_TOKEN: ${{ inputs.SLACK_BOT_TOKEN }} with: channel-id: ${{ inputs.SLACK_SUCCESS_CHANNEL_ID }} payload: | { - "text": "EKS Deplloyment Succeeded", + "text": "EKS Deployment Succeeded", "blocks": [ { "type": "header", @@ -149,11 +137,11 @@ runs: }, { "type": "mrkdwn", - "text": "${{ format('', github.repository, github.sha, steps.set-branch.outputs.branch)}}" + "text": "${{ format('', github.repository, github.sha, steps.branch-info.outputs.branch)}}" }, { "type": "mrkdwn", - "text": "${{ steps.get-short-sha.outputs.short_sha }}" + "text": "${{ steps.branch-info.outputs.short_sha }}" } ] }, @@ -172,8 +160,8 @@ runs: ] } - name: Notify slack channel on failure - if: failure() && inputs.SLACK_FAILURE_CHANNEL_ID != null - uses: slackapi/slack-github-action@v1.24.0 + if: failure() && inputs.SLACK_FAILURE_CHANNEL_ID != '' + uses: slackapi/slack-github-action@v1.27.1 env: SLACK_BOT_TOKEN: ${{ inputs.SLACK_BOT_TOKEN }} with: @@ -221,11 +209,11 @@ runs: }, { "type": "mrkdwn", - "text": "${{ format('', github.repository, github.sha, steps.set-branch.outputs.branch)}}" + "text": "${{ format('', github.repository, github.sha, steps.branch-info.outputs.branch)}}" }, { "type": "mrkdwn", - "text": "${{ steps.get-short-sha.outputs.short_sha }}" + "text": "${{ steps.branch-info.outputs.short_sha }}" } ] }, diff --git a/go/build-and-test/action.yml b/go/build-and-test/action.yml index b4e0053..48c11cf 100644 --- a/go/build-and-test/action.yml +++ b/go/build-and-test/action.yml @@ -40,21 +40,9 @@ inputs: runs: using: "composite" steps: - - name: Set branch variable - id: set-branch - shell: bash - run: | - if [ "${{ github.event_name }}" == "pull_request" ]; then - branch="${{ github.event.pull_request.head.ref }}" - else - branch="${{ github.ref }}" - branch="${branch#refs/heads/}" - fi - echo "branch=${branch}" >> $GITHUB_OUTPUT - - name: Get short sha - id: get-short-sha - run: echo "short_sha=`echo ${GITHUB_SHA::7}`" > $GITHUB_OUTPUT - shell: bash + - name: Get branch and commit info + id: branch-info + uses: wishabi/github-actions/common/branch-info@v0 - name: Run custom Go build action uses: wishabi/github-actions/go/build@v0 with: @@ -72,8 +60,8 @@ runs: TAGS: ${{ inputs.TEST_TAGS }} TIMEOUT: ${{ inputs.TIMEOUT }} - name: Notify slack channel on failure - if: failure() && inputs.SLACK_CHANNEL_ID != null && github.ref == 'refs/heads/main' - uses: slackapi/slack-github-action@v1.24.0 + if: failure() && inputs.SLACK_CHANNEL_ID != '' && github.ref == 'refs/heads/main' + uses: slackapi/slack-github-action@v1.27.1 env: SLACK_BOT_TOKEN: ${{ inputs.SLACK_BOT_TOKEN }} with: @@ -97,7 +85,7 @@ runs: "type": "section", "text": { "type": "mrkdwn", - "text": "*Repository*\n\n\n*${{ github.event_name == 'pull_request' && 'Pull Request' || 'Branch' }}*\n${{ github.event_name == 'pull_request' && format('<{0}|{1}>', github.event.pull_request.html_url, github.event.pull_request.title) || format('', github.repository, github.sha, steps.set-branch.outputs.branch)}}" + "text": "*Repository*\n\n\n*${{ github.event_name == 'pull_request' && 'Pull Request' || 'Branch' }}*\n${{ github.event_name == 'pull_request' && format('<{0}|{1}>', github.event.pull_request.html_url, github.event.pull_request.title) || format('', github.repository, github.sha, steps.branch-info.outputs.branch)}}" }, "accessory": { "type": "image", @@ -121,7 +109,7 @@ runs: }, { "type": "mrkdwn", - "text": "${{ steps.get-short-sha.outputs.short_sha }}" + "text": "${{ steps.branch-info.outputs.short_sha }}" }, { "type": "mrkdwn", diff --git a/go/build/action.yml b/go/build/action.yml index 363631d..4b8572c 100644 --- a/go/build/action.yml +++ b/go/build/action.yml @@ -21,21 +21,9 @@ inputs: runs: using: "composite" steps: - - name: Set branch variable - id: set-branch - shell: bash - run: | - if [ "${{ github.event_name }}" == "pull_request" ]; then - branch="${{ github.event.pull_request.head.ref }}" - else - branch="${{ github.ref }}" - branch="${branch#refs/heads/}" - fi - echo "branch=${branch}" >> $GITHUB_OUTPUT - - name: Get short sha - id: get-short-sha - run: echo "short_sha=`echo ${GITHUB_SHA::7}`" > $GITHUB_OUTPUT - shell: bash + - name: Get branch and commit info + id: branch-info + uses: wishabi/github-actions/common/branch-info@v0 - name: Configure Go environment uses: wishabi/github-actions/go/configure@v0 with: @@ -48,9 +36,26 @@ runs: BUF_TOKEN: ${{ inputs.BUF_BUILD_API_TOKEN }} with: FLIPPCIRCLECIPULLER_REPO_TOKEN: ${{ inputs.FLIPPCIRCLECIPULLER_REPO_TOKEN }} + - name: Write build summary + if: always() + shell: bash + run: | + echo "## Go Build Results" >> $GITHUB_STEP_SUMMARY + echo "| Setting | Value |" >> $GITHUB_STEP_SUMMARY + echo "|---------|-------|" >> $GITHUB_STEP_SUMMARY + echo "| Go | $(go version | awk '{print $3}') |" >> $GITHUB_STEP_SUMMARY + echo "| Repository | ${{ github.repository }} |" >> $GITHUB_STEP_SUMMARY + echo "| Commit | ${{ steps.branch-info.outputs.short_sha }} |" >> $GITHUB_STEP_SUMMARY + if [ "${{ job.status }}" = "success" ]; then + echo "" >> $GITHUB_STEP_SUMMARY + echo "> Build passed" >> $GITHUB_STEP_SUMMARY + else + echo "" >> $GITHUB_STEP_SUMMARY + echo "> **Build failed** — check the logs above for details" >> $GITHUB_STEP_SUMMARY + fi - name: Notify slack channel on failure - if: failure() && inputs.SLACK_CHANNEL_ID != null && github.ref == 'refs/heads/main' - uses: slackapi/slack-github-action@v1.24.0 + if: failure() && inputs.SLACK_CHANNEL_ID != '' && github.ref == 'refs/heads/main' + uses: slackapi/slack-github-action@v1.27.1 env: SLACK_BOT_TOKEN: ${{ inputs.SLACK_BOT_TOKEN }} with: @@ -74,7 +79,7 @@ runs: "type": "section", "text": { "type": "mrkdwn", - "text": "*Repository*\n\n\n*${{ github.event_name == 'pull_request' && 'Pull Request' || 'Branch' }}*\n${{ github.event_name == 'pull_request' && format('<{0}|{1}>', github.event.pull_request.html_url, github.event.pull_request.title) || format('', github.repository, github.sha, steps.set-branch.outputs.branch)}}" + "text": "*Repository*\n\n\n*${{ github.event_name == 'pull_request' && 'Pull Request' || 'Branch' }}*\n${{ github.event_name == 'pull_request' && format('<{0}|{1}>', github.event.pull_request.html_url, github.event.pull_request.title) || format('', github.repository, github.sha, steps.branch-info.outputs.branch)}}" }, "accessory": { "type": "image", @@ -98,7 +103,7 @@ runs: }, { "type": "mrkdwn", - "text": "${{ steps.get-short-sha.outputs.short_sha }}" + "text": "${{ steps.branch-info.outputs.short_sha }}" }, { "type": "mrkdwn", diff --git a/go/deps/action.yml b/go/deps/action.yml index b96883b..4aa01e4 100644 --- a/go/deps/action.yml +++ b/go/deps/action.yml @@ -28,6 +28,13 @@ runs: if: ${{ hashFiles('buf.gen.yaml') != '' }} run: buf generate shell: bash + - name: Log tool versions + shell: bash + run: | + echo "::group::Tool Versions" + echo "Go: $(go version)" + if command -v buf &> /dev/null; then echo "Buf: $(buf --version)"; fi + echo "::endgroup::" - name: Setting up private modules access if: steps.vendor-cache.outputs.cache-hit != 'true' shell: bash @@ -81,5 +88,11 @@ runs: if: ${{ hashFiles('.mockery.yml') != '' }} run: mockery shell: bash + - name: Log generated tool versions + shell: bash + run: | + echo "::group::Generated Tool Versions" + if command -v mockery &> /dev/null; then echo "Mockery: $(mockery --version 2>/dev/null || echo 'installed but version unknown')"; fi + echo "::endgroup::" - name: Caching workspace for deploy jobs uses: wishabi/github-actions/cache@v0 diff --git a/go/lint/action.yml b/go/lint/action.yml index 640cfd7..a607567 100644 --- a/go/lint/action.yml +++ b/go/lint/action.yml @@ -29,21 +29,9 @@ inputs: runs: using: "composite" steps: - - name: Set branch variable - id: set-branch - shell: bash - run: | - if [ "${{ github.event_name }}" == "pull_request" ]; then - branch="${{ github.event.pull_request.head.ref }}" - else - branch="${{ github.ref }}" - branch="${branch#refs/heads/}" - fi - echo "branch=${branch}" >> $GITHUB_OUTPUT - - name: Get short sha - id: get-short-sha - run: echo "short_sha=`echo ${GITHUB_SHA::7}`" > $GITHUB_OUTPUT - shell: bash + - name: Get branch and commit info + id: branch-info + uses: wishabi/github-actions/common/branch-info@v0 - name: Configure Go environment uses: wishabi/github-actions/go/configure@v0 with: @@ -85,23 +73,49 @@ runs: echo "IS_V2=${IS_V2}" >> $GITHUB_ENV echo "GOLANGCI_LINT_VERSION=${GOLANGCI_LINT_VERSION}" >> $GITHUB_ENV shell: bash + - name: Log tool versions + shell: bash + run: | + echo "::group::Tool Versions" + echo "Go: $(go version)" + if [ -n "${{ env.GOLANGCI_LINT_VERSION }}" ]; then echo "golangci-lint: ${{ env.GOLANGCI_LINT_VERSION }}"; fi + echo "::endgroup::" - name: Run v1 Go linter - if : ${{ env.IS_V2 == 'false' }} + if: ${{ env.IS_V2 == 'false' }} uses: golangci/golangci-lint-action@v6 with: skip-cache: true args: --verbose version: ${{ env.GOLANGCI_LINT_VERSION }} # Optional - if blank, will use the action's default version resolution - name: Run v2 Go linter - if : ${{ env.IS_V2 == 'true' }} + if: ${{ env.IS_V2 == 'true' }} uses: golangci/golangci-lint-action@v7 # Note: v7 and up require golangci-lint v2 config with: skip-cache: true args: --verbose version: ${{ env.GOLANGCI_LINT_VERSION }} # Optional - if blank, will use the action's default version resolution + - name: Write lint summary + if: always() + shell: bash + run: | + echo "## Go Lint Results" >> $GITHUB_STEP_SUMMARY + echo "| Setting | Value |" >> $GITHUB_STEP_SUMMARY + echo "|---------|-------|" >> $GITHUB_STEP_SUMMARY + echo "| Go | $(go version | awk '{print $3}') |" >> $GITHUB_STEP_SUMMARY + if [ -n "${{ env.GOLANGCI_LINT_VERSION }}" ]; then + echo "| golangci-lint | ${{ env.GOLANGCI_LINT_VERSION }} |" >> $GITHUB_STEP_SUMMARY + fi + echo "| Config version | ${{ env.IS_V2 == 'true' && 'v2' || 'v1' }} |" >> $GITHUB_STEP_SUMMARY + if [ "${{ job.status }}" = "success" ]; then + echo "" >> $GITHUB_STEP_SUMMARY + echo "> Lint passed" >> $GITHUB_STEP_SUMMARY + else + echo "" >> $GITHUB_STEP_SUMMARY + echo "> **Lint failed** — check the logs above for details" >> $GITHUB_STEP_SUMMARY + fi - name: Notify slack channel on failure - if: failure() && inputs.SLACK_CHANNEL_ID != null && github.ref == 'refs/heads/main' - uses: slackapi/slack-github-action@v1.24.0 + if: failure() && inputs.SLACK_CHANNEL_ID != '' && github.ref == 'refs/heads/main' + uses: slackapi/slack-github-action@v1.27.1 env: SLACK_BOT_TOKEN: ${{ inputs.SLACK_BOT_TOKEN }} with: @@ -125,7 +139,7 @@ runs: "type": "section", "text": { "type": "mrkdwn", - "text": "*Repository*\n\n\n*${{ github.event_name == 'pull_request' && 'Pull Request' || 'Branch' }}*\n${{ github.event_name == 'pull_request' && format('<{0}|{1}>', github.event.pull_request.html_url, github.event.pull_request.title) || format('', github.repository, github.sha, steps.set-branch.outputs.branch)}}" + "text": "*Repository*\n\n\n*${{ github.event_name == 'pull_request' && 'Pull Request' || 'Branch' }}*\n${{ github.event_name == 'pull_request' && format('<{0}|{1}>', github.event.pull_request.html_url, github.event.pull_request.title) || format('', github.repository, github.sha, steps.branch-info.outputs.branch)}}" }, "accessory": { "type": "image", @@ -149,7 +163,7 @@ runs: }, { "type": "mrkdwn", - "text": "${{ steps.get-short-sha.outputs.short_sha }}" + "text": "${{ steps.branch-info.outputs.short_sha }}" }, { "type": "mrkdwn", diff --git a/go/smoke-test/action.yml b/go/smoke-test/action.yml index 92257ca..fe35af0 100644 --- a/go/smoke-test/action.yml +++ b/go/smoke-test/action.yml @@ -32,21 +32,9 @@ inputs: runs: using: 'composite' steps: - - name: Set branch variable - id: set-branch - shell: bash - run: | - if [ "${{ github.event_name }}" == "pull_request" ]; then - branch="${{ github.event.pull_request.head.ref }}" - else - branch="${{ github.ref }}" - branch="${branch#refs/heads/}" - fi - echo "branch=${branch}" >> $GITHUB_OUTPUT - - name: Get short sha - id: get-short-sha - run: echo "short_sha=`echo ${GITHUB_SHA::7}`" > $GITHUB_OUTPUT - shell: bash + - name: Get branch and commit info + id: branch-info + uses: wishabi/github-actions/common/branch-info@v0 - name: Restore cache uses: wishabi/github-actions/cache@v0 - name: Run Go Smoke Tests @@ -55,12 +43,30 @@ runs: go test ./tests/smoke --tags=smoke shell: bash - name: Run DataDog Synthetics - if: inputs.DD_SYNTHETIC_IDS != null - uses: DataDog/synthetics-ci-github-action@v0.20.0 + if: inputs.DD_SYNTHETIC_IDS != '' + uses: DataDog/synthetics-ci-github-action@v1.17.0 with: api_key: ${{ inputs.DD_API_KEY }} app_key: ${{ inputs.DD_APP_KEY }} public_ids: ${{ inputs.DD_SYNTHETIC_IDS }} + - name: Write smoke test summary + if: always() + shell: bash + run: | + echo "## Smoke Test Results" >> $GITHUB_STEP_SUMMARY + echo "| Setting | Value |" >> $GITHUB_STEP_SUMMARY + echo "|---------|-------|" >> $GITHUB_STEP_SUMMARY + echo "| Environment | ${{ inputs.ENV }} |" >> $GITHUB_STEP_SUMMARY + echo "| Go Smoke | ${{ inputs.GO_SMOKE }} |" >> $GITHUB_STEP_SUMMARY + echo "| DataDog Synthetics | ${{ inputs.DD_SYNTHETIC_IDS != '' && 'yes' || 'no' }} |" >> $GITHUB_STEP_SUMMARY + echo "| Rollback on Fail | ${{ inputs.ROLLBACK_ON_FAIL }} |" >> $GITHUB_STEP_SUMMARY + if [ "${{ job.status }}" = "success" ]; then + echo "" >> $GITHUB_STEP_SUMMARY + echo "> Smoke tests passed" >> $GITHUB_STEP_SUMMARY + else + echo "" >> $GITHUB_STEP_SUMMARY + echo "> **Smoke tests failed** — check the logs above for details" >> $GITHUB_STEP_SUMMARY + fi - name: Rollback on failure if: failure() && inputs.ROLLBACK_ON_FAIL == 'true' run: | @@ -68,8 +74,8 @@ runs: chmod +x ./deploy/build.sh && ./deploy/build.sh service rollback --env=${{ inputs.ENV }} shell: bash - name: Notify slack channel on failure - if: failure() && inputs.SLACK_CHANNEL_ID != null - uses: slackapi/slack-github-action@v1.24.0 + if: failure() && inputs.SLACK_CHANNEL_ID != '' + uses: slackapi/slack-github-action@v1.27.1 env: SLACK_BOT_TOKEN: ${{ inputs.SLACK_BOT_TOKEN }} with: @@ -109,11 +115,11 @@ runs: "fields": [ { "type": "mrkdwn", - "text": "*Branch*\n${{ format('', github.repository, github.sha, steps.set-branch.outputs.branch)}}" + "text": "*Branch*\n${{ format('', github.repository, github.sha, steps.branch-info.outputs.branch)}}" }, { "type": "mrkdwn", - "text": "*Commit*\n${{ steps.get-short-sha.outputs.short_sha }}" + "text": "*Commit*\n${{ steps.branch-info.outputs.short_sha }}" }, { "type": "mrkdwn", diff --git a/go/test/action.yml b/go/test/action.yml index 2f70c5e..2a5dd3c 100644 --- a/go/test/action.yml +++ b/go/test/action.yml @@ -13,6 +13,10 @@ inputs: description: Whether to run tests in parallel. Defaults to true. required: false default: "true" + ARTIFACT_RETENTION_DAYS: + description: Number of days to retain test and coverage artifacts. + required: false + default: "1" runs: using: 'composite' @@ -20,15 +24,41 @@ runs: - name: Running go tests shell: bash run: ${GITHUB_ACTION_PATH}/test.sh "${{ inputs.TAGS }}" "${{ inputs.TIMEOUT }}" "${{ inputs.PARALLEL }}" + - name: Write test summary + if: always() + shell: bash + run: | + echo "## Go Test Results" >> $GITHUB_STEP_SUMMARY + if [ -f test-report.out ]; then + PASS=$(grep -c '^--- PASS:' test-report.out || true) + FAIL=$(grep -c '^--- FAIL:' test-report.out || true) + SKIP=$(grep -c '^--- SKIP:' test-report.out || true) + echo "| Status | Count |" >> $GITHUB_STEP_SUMMARY + echo "|--------|-------|" >> $GITHUB_STEP_SUMMARY + echo "| Passed | ${PASS} |" >> $GITHUB_STEP_SUMMARY + echo "| Failed | ${FAIL} |" >> $GITHUB_STEP_SUMMARY + echo "| Skipped | ${SKIP} |" >> $GITHUB_STEP_SUMMARY + if [ "$FAIL" -gt 0 ]; then + echo "" >> $GITHUB_STEP_SUMMARY + echo "
Failed Tests" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + grep '^--- FAIL:' test-report.out >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + echo "
" >> $GITHUB_STEP_SUMMARY + fi + else + echo "> **Warning:** No test report found" >> $GITHUB_STEP_SUMMARY + fi - name: Uploading test report uses: actions/upload-artifact@v4 with: name: "${{ github.sha }}-test-report.out" path: "./test-report.out" - retention-days: 1 + retention-days: ${{ inputs.ARTIFACT_RETENTION_DAYS }} - name: Uploading coverage report uses: actions/upload-artifact@v4 with: name: "${{ github.sha }}-coverage.out" path: "./coverage.out" - retention-days: 1 + retention-days: ${{ inputs.ARTIFACT_RETENTION_DAYS }} diff --git a/go/test/test.sh b/go/test/test.sh index d84d250..baff573 100755 --- a/go/test/test.sh +++ b/go/test/test.sh @@ -1,11 +1,11 @@ #! /bin/bash -set -e +set -eu -TAGS=$1 -TIMEOUT=$2 -PARALLEL=$3 +TAGS=${1:-} +TIMEOUT=${2:-} +PARALLEL=${3:-} -cmd="go test 2>&1 ./... -coverprofile=coverage.out" +cmd="go test ./... -coverprofile=coverage.out" # find non-ignored subdirectories file_list=() @@ -36,7 +36,7 @@ if [ "$PARALLEL" = "false" ]; then cmd="$cmd -p 1" fi -echo "$cmd | tee test-report.out" -eval "$cmd" | tee test-report.out +echo "$cmd | tee test-report.out" +bash -c "$cmd" 2>&1 | tee test-report.out exit ${PIPESTATUS[0]} diff --git a/ruby/lint/action.yml b/ruby/lint/action.yml index e496065..df58de1 100644 --- a/ruby/lint/action.yml +++ b/ruby/lint/action.yml @@ -1,6 +1,12 @@ name: 'Lint - rubocop' description: 'Lints using rubocop' +inputs: + ARTIFACT_RETENTION_DAYS: + description: Number of days to retain lint result artifacts. + required: false + default: "1" + runs: using: "composite" steps: @@ -16,4 +22,4 @@ runs: with: name: "${{ github.sha }}-lint-results.out" path: ./rubocop/rubocop.json - retention-days: 1 + retention-days: ${{ inputs.ARTIFACT_RETENTION_DAYS }} diff --git a/ruby/test/action.yml b/ruby/test/action.yml index bb9099f..945df0d 100644 --- a/ruby/test/action.yml +++ b/ruby/test/action.yml @@ -16,6 +16,10 @@ inputs: description: Set this if you want to use db:schema:load before db:migrate. default: "" required: false + ARTIFACT_RETENTION_DAYS: + description: Number of days to retain test and coverage artifacts. + required: false + default: "1" runs: using: "composite" @@ -63,10 +67,10 @@ runs: with: name: ${{ github.sha }}-coverage.out path: ./coverage/coverage.json - retention-days: 1 + retention-days: ${{ inputs.ARTIFACT_RETENTION_DAYS }} - name: 'Upload test results' uses: actions/upload-artifact@v4 with: name: ${{ github.sha }}-test-report.out path: ./result/rspec.xml - retention-days: 1 + retention-days: ${{ inputs.ARTIFACT_RETENTION_DAYS }} diff --git a/slack/action.yml b/slack/action.yml index 828b58b..f1596ac 100644 --- a/slack/action.yml +++ b/slack/action.yml @@ -11,22 +11,14 @@ inputs: runs: using: "composite" steps: - - name: Set BRANCH variable - id: set-branch - shell: bash - run: | - if [ "${{ github.event_name }}" == "pull_request" ]; then - BRANCH="${{ github.event.pull_request.head.ref }}" - else - BRANCH="${{ github.ref }}" - BRANCH="${BRANCH#refs/heads/}" - fi - echo "BRANCH=${BRANCH}" >> $GITHUB_ENV + - name: Get branch and commit info + id: branch-info + uses: wishabi/github-actions/common/branch-info@v0 - name: Get Unix Timestamp id: timestamp-step shell: bash - run: echo "::set-output name=timestamp::$(date +%s)" - - uses: slackapi/slack-github-action@v1.24.0 + run: echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT + - uses: slackapi/slack-github-action@v1.27.1 env: SLACK_BOT_TOKEN: ${{ inputs.SLACK_BOT_TOKEN }} with: @@ -50,7 +42,7 @@ runs: }, { "title": "${{ github.event_name == 'pull_request' && 'Pull Request' || 'Branch' }}", - "value": "${{ github.event_name == 'pull_request' && format('<{0} | {1}>', github.event.pull_request.html_url, github.event.pull_request.title) || format('', github.repository, github.sha, env.BRANCH)}}", + "value": "${{ github.event_name == 'pull_request' && format('<{0} | {1}>', github.event.pull_request.html_url, github.event.pull_request.title) || format('', github.repository, github.sha, steps.branch-info.outputs.branch)}}", "short": true }, { diff --git a/sonarqube-scan/action.yml b/sonarqube-scan/action.yml deleted file mode 100644 index 43fd16f..0000000 --- a/sonarqube-scan/action.yml +++ /dev/null @@ -1,116 +0,0 @@ -name: "SonarQube Scan" -description: "Runs various quality and security checks against changes" -inputs: - SONAR_HOST_URL: - description: secret value - required: true - SONAR_TOKEN: - description: secret value - required: true - CHECK_LINTER: - description: whether to download and analyze linter results - default: false - SLACK_CHANNEL_ID: - description: The Slack channel ID(s) to send the data to - required: false - SLACK_BOT_TOKEN: - description: The Slack bot token to pass the data to - required: false - -runs: - using: "composite" - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Set branch variable - id: set-branch - shell: bash - run: | - if [ "${{ github.event_name }}" == "pull_request" ]; then - branch="${{ github.event.pull_request.head.ref }}" - else - branch="${{ github.ref }}" - branch="${branch#refs/heads/}" - fi - echo "branch=${branch}" >> $GITHUB_OUTPUT - - name: Get short sha - id: get-short-sha - run: echo "short_sha=`echo ${GITHUB_SHA::7}`" > $GITHUB_OUTPUT - shell: bash - - name: Downloading test report - uses: actions/download-artifact@v4 - with: - name: "${{ github.sha }}-test-report.out" - - name: Downloading coverage report - uses: actions/download-artifact@v4 - with: - name: "${{ github.sha }}-coverage.out" - - name: Download linter results - if: ${{ inputs.CHECK_LINTER == 'true' }} - uses: actions/download-artifact@v4 - with: - name: "${{ github.sha }}-lint-results.out" - - name: SonarQube Scan - uses: sonarsource/sonarqube-scan-action@v3.1.0 - env: - SONAR_TOKEN: ${{ inputs.SONAR_TOKEN }} - SONAR_HOST_URL: ${{ inputs.SONAR_HOST_URL }} - with: - args: > - -Dsonar.projectVersion=${{ steps.get-short-sha.outputs.short_sha }} - - name: Notify slack channel on failure - if: failure() && inputs.SLACK_CHANNEL_ID != null && github.ref == 'refs/heads/main' - uses: slackapi/slack-github-action@v1.24.0 - env: - SLACK_BOT_TOKEN: ${{ inputs.SLACK_BOT_TOKEN }} - with: - channel-id: ${{ inputs.SLACK_CHANNEL_ID }} - payload: | - { - "text": "SonarQube Scan Failed", - "blocks": [ - { - "type": "header", - "text": { - "type": "plain_text", - "text": "SonarQube Scan Failed", - "emoji": true - } - }, - { - "type": "divider" - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*Repository*\n\n\n*${{ github.event_name == 'pull_request' && 'Pull Request' || 'Branch' }}*\n${{ github.event_name == 'pull_request' && format('<{0}|{1}>', github.event.pull_request.html_url, github.event.pull_request.title) || format('', github.repository, github.sha, steps.set-branch.outputs.branch)}}" - }, - "accessory": { - "type": "image", - "image_url": "https://emoji.slack-edge.com/T02AJQYGN/sonar-fail/3d49949af6831e63.png", - "alt_text": "sonar fail icon" - } - }, - { - "type": "divider" - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*Commit*\n${{ steps.get-short-sha.outputs.short_sha }}" - } - }, - { - "type": "context", - "elements": [ - { - "type": "mrkdwn", - "text": "*Triggered By:* ${{ github.triggering_actor }}" - } - ] - } - ] - }