Skip to content

Commit

Permalink
Merge pull request deriv-com#48 from fasihali-deriv/resolve-conflicts…
Browse files Browse the repository at this point in the history
…-round-2

Fasih/ Resolve conflicts
  • Loading branch information
amina-deriv authored Jun 7, 2024
2 parents 90e2ec6 + a34e7bc commit 1d184de
Show file tree
Hide file tree
Showing 682 changed files with 8,221 additions and 18,793 deletions.
106 changes: 75 additions & 31 deletions .github/actions/analyze/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,31 @@ inputs:
ISSUE_NUMBER:
description: 'Issue to post a comment to'
required: false
TRUSTPILOT_API_KEY:
description: 'Trustpilot api key'
required: false

runs:
using: composite
steps:

- name: Get artifact URL
id: get_artifact_url
env:
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
shell: bash
run: |
ARTIFACT_URL=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts" | \
jq -r '.artifacts | map(select(.workflow_run.head_branch == "master" and (.name | startswith("reports-")))) | .[0] | .archive_download_url')
RESPONSE=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts?name=analyse")
ARTIFACT_URL=$(echo $RESPONSE | jq -r '.artifacts[0].archive_download_url')
if [[ -z "$ARTIFACT_URL" ]]; then
echo "Error: No artifact URL found for the master branch with prefix 'analyse'."
exit 1
else
echo "Artifact URL: $ARTIFACT_URL"
fi
echo "artifact_url=$ARTIFACT_URL" >> $GITHUB_OUTPUT
echo "artifact_url=$ARTIFACT_URL"
Expand All @@ -89,7 +100,7 @@ runs:
-o artifact.zip
unzip artifact.zip -d old
cd old
unzip reports.zip
unzip analyse.zip
- name: Analyze all packages
env:
Expand All @@ -110,6 +121,7 @@ runs:
GROWTHBOOK_DECRYPTION_KEY: ${{ inputs.GROWTHBOOK_DECRYPTION_KEY }}
REF_NAME: ${{ inputs.REF_NAME }}
REMOTE_CONFIG_URL: ${{ inputs.REMOTE_CONFIG_URL }}
TRUSTPILOT_API_KEY: ${{ inputs.TRUSTPILOT_API_KEY }}
NODE_OPTIONS: "--max_old_space_size=4096"
shell: bash
run: npm run build:prod && npm run analyze:stats && npm run analyze:build
Expand All @@ -119,37 +131,69 @@ runs:
if: steps.get_artifact_url.outputs.artifact_url != 'null'
shell: bash
run: |
DIFF_OUTPUT=$(node .github/actions/analyze/compareReports.js)
echo "diff_output<<EOF" >> $GITHUB_OUTPUT
echo "$DIFF_OUTPUT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo $DIFF_OUTPUT
DIFF_OUTPUT_HTML=$(node .github/actions/analyze/compareReports.js --format=html)
ABOVE_THRESHOLD=$(node .github/actions/analyze/compareReports.js --format=boolean) || { echo "Threshold check failed"; exit 1; }
# Output results to GITHUB_OUTPUT
echo "diff_output_html=$DIFF_OUTPUT_HTML" >> $GITHUB_OUTPUT
echo "above_threshold=$ABOVE_THRESHOLD" >> $GITHUB_OUTPUT
- name: Comment on PR with Diff Output
if: steps.get_artifact_url.outputs.artifact_url != 'null' && inputs.ISSUE_NUMBER
uses: actions/github-script@v5
env:
DIFF_OUTPUT_HTML: ${{ steps.diff.outputs.diff_output_html }}
ISSUE_NUMBER: ${{ inputs.ISSUE_NUMBER }}
with:
script: |
const diffOutputHtml = process.env.DIFF_OUTPUT_HTML; // Removed Buffer.from and base64 decoding
const issueNumber = process.env.ISSUE_NUMBER;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: `${diffOutputHtml}`
});
continue-on-error: true

- name: Print out differences on console
id: print_diff
if: steps.get_artifact_url.outputs.artifact_url != 'null'
shell: bash
run: |
node .github/actions/analyze/compareReports.js --format=console
# - name: Comment on PR with Diff Output
# if: steps.get_artifact_url.outputs.artifact_url != 'null' && inputs.ISSUE_NUMBER
# uses: actions/github-script@v5
# env:
# DIFF_OUTPUT: ${{ steps.diff.outputs.diff_output }}
# ISSUE_NUMBER: ${{ inputs.ISSUE_NUMBER }}
# with:
# script: |
# const diffOutput = process.env.DIFF_OUTPUT;
# const issueNumber = process.env.ISSUE_NUMBER;
# github.rest.issues.createComment({
# owner: context.repo.owner,
# repo: context.repo.repo,
# issue_number: issueNumber,
# body: `${diffOutput}`
# });
- name: Validate size changes
if: ${{ steps.diff.outputs.above_threshold == 'true' }}
uses: actions/github-script@v5
with:
script: |
core.setFailed('Size changes exceed the defined threshold. Check above logs for details.');
- name: Zip all report.json files
shell: bash
run: |
zip -r reports.zip packages/*/report.json
zip -r analyse.zip packages/*/report.json
- name: Upload analyse.zip for Master Branch
if: github.ref == 'refs/heads/master'
uses: actions/upload-artifact@v4
with:
name: analyse
path: analyse.zip
retention-days: 20

- name: Set sanitized branch name
id: sanitize
shell: bash
run: |
SANITIZED_REF_NAME=$(echo "${{ github.ref_name }}" | sed 's/[^a-zA-Z0-9]/-/g')
echo "SANITIZED_REF_NAME=${SANITIZED_REF_NAME}" >> $GITHUB_ENV
- name: Upload reports.zip
- name: Upload analyse.zip for Feature Branches
if: github.ref != 'refs/heads/master'
uses: actions/upload-artifact@v4
with:
name: reports-${{ github.sha }}
path: reports.zip
retention-days: 5
name: analyse-${{ env.SANITIZED_REF_NAME }}
path: analyse.zip
retention-days: 5
Loading

0 comments on commit 1d184de

Please sign in to comment.