Skip to content

Commit

Permalink
ci: DOC-1597 CI/CD Error Catching (#5451)
Browse files Browse the repository at this point in the history
* ci: adding set -e

* ci: more test

* ci: more test

* ci: test with exit code 5

* ci: not set -e

* ci: DOC-1597

* ci: removed script

* docs: updated README

* docs: format fix

* chore: fix mistake

* ci: retest

* ci: mock test for 5

* ci: test with 5

* ci: test with 5

* ci: clean build test

* ci: ready for merge

* docs: apply suggestions from code review

Co-authored-by: Adelina Simion <[email protected]>

* ci: added logic for retry

* docs: updated comment

---------

Co-authored-by: Adelina Simion <[email protected]>
  • Loading branch information
karl-cardenas-coding and addetz authored Jan 16, 2025
1 parent 3b6f577 commit 5da6cf8
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/actions/build-cached-cves/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ runs:
run: |
rm -rf build
npm run build
exit_code=$?
echo "BUILD_EXIT_CODE=$$exit_code" >> $GITHUB_ENV
shell: bash
2 changes: 2 additions & 0 deletions .github/actions/build-cached-packs/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ runs:
run: |
rm -rf build
npm run build
exit_code=$?
echo "BUILD_EXIT_CODE=$$exit_code" >> $GITHUB_ENV
shell: bash
3 changes: 2 additions & 1 deletion .github/workflows/release-preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
run: |
set +e # Disable automatic stop on command failure
touch .env
make build
make build-ci
exit_code=$?
echo "Build command exit code: $exit_code"
echo "BUILD_EXIT_CODE=$exit_code">> $GITHUB_ENV
Expand All @@ -77,6 +77,7 @@ jobs:
gh-token: ${{ secrets.GITHUB_TOKEN }}

- name: Deploy Preview
if: ${{ env.BUILD_EXIT_CODE == '0' }}
run: |
aws s3 sync --cache-control 'public, max-age=604800' --exclude '*.html' --exclude build/scripts/ build/ s3://docs-latest.spectrocloud.com --delete
aws s3 sync --cache-control 'public, max-age=0, s-maxage=604800' build/ s3://docs-latest.spectrocloud.com --delete
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
touch .env
make versions-ci
make build-ci
- name: Build with cached packs
if: ${{ env.BUILD_EXIT_CODE == '5' }}
uses: ./.github/actions/build-cached-packs
Expand All @@ -81,14 +81,15 @@ jobs:
gh-token: ${{ secrets.GITHUB_TOKEN }}

- name: Upload to AWS
if: ${{ env.BUILD_EXIT_CODE == '0' }}
run: |
echo "CURRENT_STEP=Upload to AWS" >> $GITHUB_ENV
aws s3 sync --cache-control 'public, max-age=604800' --exclude '*.html' --exclude '*.xml' --exclude build/scripts/ build/ s3://docs.spectrocloud.com --delete
aws s3 sync --cache-control 'public, max-age=0, s-maxage=604800' build/ s3://docs.spectrocloud.com --delete
aws cloudfront create-invalidation --distribution-id ${{ secrets.DISTRIBUTION_ID }} --paths "/*"
- name: Slack Notification on Failure
if: ${{ failure() }}
if: ${{ failure() || env.BUILD_EXIT_CODE != '0' }}
uses: rtCamp/[email protected]
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_PRIVATE_TEAM_WEBHOOK }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/screenshot_capture.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ jobs:
gh-token: ${{ secrets.GITHUB_TOKEN }}

- name: Upload Build
if: ${{ env.BUILD_EXIT_CODE == '0' }}
uses: actions/upload-artifact@v4
with:
name: "build"
Expand Down
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,25 @@ build-cached-cves: ## Run npm build with cached CVEs retry
fi; \
}


# This step is designed to always return a positive exit code due to the echo that outputs the exit code.
# This is by design to ensure that the build step does not fail and subsequent GitHub Actions steps can execute that are dependent on the exit code.
# It may be counterintuitive, but it is necessary to ensure that the build CI workflow does not fails completely without providing an opportunity for the retry steps that check the exit code.
build-ci: ## Run npm build in CI environment
@echo "building site"
npm run clear
rm -rf build
@{ \
npm run build; \
exit_code=$$?; \
echo "Build exited with code $$exit_code..."; \
echo "BUILD_EXIT_CODE=$$exit_code" >> $(GITHUB_ENV); \
echo "Build exited with code $$exit_code..."; \
if [ $$exit_code -ne 0 ] && [ $$exit_code -ne 5 ] && [ $$exit_code -ne 7 ]; then \
echo "Unacceptable exit code: $$exit_code"; \
exit 1; \
fi; \
}


versions: ## Create Docusarus content versions
@echo "creating versions"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,10 @@ make clean-versions
Librarium provides the following exit codes. These exit codes are returned by both the `npm run start` and
`npm run build` commands.

> [!NOTE]
>
> Any exit codes added to the table must also be added to the Makefile's `build-ci` command.
| **Exit Code** | **Description** |
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `0` | The command was executed successfully. |
Expand Down

0 comments on commit 5da6cf8

Please sign in to comment.