Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: get the last successful master artifact #15253

Merged
merged 4 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 11 additions & 27 deletions .github/actions/analyze/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,43 +57,25 @@ inputs:
IS_GROWTHBOOK_ENABLED:
description: 'Is growthbook enabled'
required: true
ISSUE_NUMBER:
description: 'Issue to post a comment to'
required: false

runs:
using: composite
steps:

- name: Get latest commit hash from master
id: latest_commit
shell: bash
run: |
git fetch origin master
latest_commit=$(git rev-parse origin/master)
echo "latest_commit=$latest_commit" >> $GITHUB_OUTPUT

- name: Check if previous artifact exists
env:
LATEST_COMMIT: ${{ steps.latest_commit.outputs.latest_commit }}
id: artifact_check
shell: bash
run: |
ARTIFACT_EXISTS=$(curl -s -H "Authorization: Bearer ${{ github.token }}" "https://api.github.com/repos/${{ github.repository }}/actions/artifacts?name=reports-$LATEST_COMMIT" | jq '.total_count' | awk '{print $1}')
if [[ $ARTIFACT_EXISTS -gt 0 ]]; then
echo "artifact_exists=true" >> $GITHUB_OUTPUT
else
echo "artifact_exists=false" >> $GITHUB_OUTPUT
fi

- name: Get artifact URL
id: get_artifact_url
env:
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
LATEST_COMMIT: ${{ steps.latest_commit.outputs.latest_commit }}
shell: bash
run: |
ARTIFACT_URL=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts?name=reports-${LATEST_COMMIT}" | \
jq -r '.artifacts[0].archive_download_url')
"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')
echo "artifact_url=$ARTIFACT_URL" >> $GITHUB_OUTPUT
echo "artifact_url=$ARTIFACT_URL"

- name: Download artifact
if: steps.get_artifact_url.outputs.artifact_url != 'null'
Expand Down Expand Up @@ -137,23 +119,25 @@ runs:
if: steps.get_artifact_url.outputs.artifact_url != 'null'
shell: bash
run: |
DIFF_OUTPUT=$(node .github/workflows/compareReports.js)
DIFF_OUTPUT=$(node .github/actions/analyze/compareReports.js)
echo "diff_output<<EOF" >> $GITHUB_OUTPUT
echo "$DIFF_OUTPUT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

- name: Comment on PR with Diff Output
if: github.event_name == 'pull_request' && steps.get_artifact_url.outputs.artifact_url != 'null'
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: ${{ github.event.pull_request.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: context.issue.number,
issue_number: issueNumber,
body: `${diffOutput}`
});

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ jobs:
GROWTHBOOK_DECRYPTION_KEY: ${{ vars.GROWTHBOOK_DECRYPTION_KEY }}
REF_NAME: ${{ github.ref_name }}
REMOTE_CONFIG_URL: ${{ vars.REMOTE_CONFIG_URL }}
ISSUE_NUMBER: ${{ github.event.pull_request.number }}
Loading