Skip to content

Commit

Permalink
Merge pull request #383 from adobe/sonarCloudGithubActions
Browse files Browse the repository at this point in the history
build: move storybook upload to post-build
  • Loading branch information
marshallpete authored Aug 9, 2024
2 parents 15f1dbc + 257d1f7 commit 77877fb
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 45 deletions.
83 changes: 42 additions & 41 deletions .github/workflows/pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,62 +34,63 @@ jobs:
- name: Test 🧪
run: yarn test

- name: Upload code coverage
- name: Build 🛠️
run: yarn build

- name: Build Storybook
run: yarn build:storybook

- name: Upload code coverage and storybook
uses: actions/upload-artifact@v4
with:
name: rsc-code-coverage
path: |
coverage/lcov.info
test-report.xml
dist-storybook/*
- name: Build 🛠️
run: yarn build

- name: Build Storybook
run: yarn build:storybook

- name: Create and Upload Storybook to PR directory
run: |
PR_NUMBER="PR-${{ github.event.number }}"
# - name: Create and Upload Storybook to PR directory
# run: |
# PR_NUMBER="PR-${{ github.event.number }}"

git config user.name "evargast"
git config user.email "[email protected]"
# git config user.name "evargast"
# git config user.email "[email protected]"

# Fetch the existing gh-pages branch
git fetch origin gh-pages
# # Fetch the existing gh-pages branch
# git fetch origin gh-pages

# Checkout the existing gh-pages branch
git checkout gh-pages
# # Checkout the existing gh-pages branch
# git checkout gh-pages

# Remove the PR directory if it exists
rm -rf "${PR_NUMBER}"
# # Remove the PR directory if it exists
# rm -rf "${PR_NUMBER}"

# Create the PR directory
mkdir "${PR_NUMBER}"
# # Create the PR directory
# mkdir "${PR_NUMBER}"

# Copy the contents of dist-storybook to the directory
cp -r dist-storybook/* "${PR_NUMBER}/"
# # Copy the contents of dist-storybook to the directory
# cp -r dist-storybook/* "${PR_NUMBER}/"

rm -rf node_modules # Explicitly remove the node_modules directory
rm -rf dist-storybook # Explicitly remove the dist-storybook directory
# rm -rf node_modules # Explicitly remove the node_modules directory
# rm -rf dist-storybook # Explicitly remove the dist-storybook directory

# Add, commit, and push changes
git add "${PR_NUMBER}/."
git commit -m "Update Storybook for ${PR_NUMBER}"
git push -f origin gh-pages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# # Add, commit, and push changes
# git add "${PR_NUMBER}/."
# git commit -m "Update Storybook for ${PR_NUMBER}"
# git push -f origin gh-pages
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Add comment to the PR with Storybook URL
run: |
PR_NUMBER="${{ github.event.number }}"
COMMENT_BODY="🎨 Storybook -> https://opensource.adobe.com/react-spectrum-charts/PR-${PR_NUMBER}"
# - name: Add comment to the PR with Storybook URL
# run: |
# PR_NUMBER="${{ github.event.number }}"
# COMMENT_BODY="🎨 Storybook -> https://opensource.adobe.com/react-spectrum-charts/PR-${PR_NUMBER}"

curl -sSL \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-X POST \
-d '{"body":"'"${COMMENT_BODY}"'"}' \
"https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments"
# curl -sSL \
# -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
# -X POST \
# -d '{"body":"'"${COMMENT_BODY}"'"}' \
# "https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments"

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57 changes: 53 additions & 4 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
name: Sonar
name: PR Post-Build
on:
workflow_run:
workflows: [PR Build]
types: [completed]
jobs:
sonar:
name: Sonar
post-build:
runs-on: ubuntu-latest
timeout-minutes: 30
if: github.event.workflow_run.conclusion == 'success'
steps:
- uses: actions/checkout@v4
- name: Checkout main
uses: actions/checkout@v4
with:
repository: ${{ github.event.workflow_run.head_repository.full_name }}
ref: ${{ github.event.workflow_run.head_branch }}
fetch-depth: 0

- name: 'Download code coverage'
uses: actions/github-script@v6
with:
Expand All @@ -35,8 +36,10 @@ jobs:
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/rsc-code-coverage.zip`, Buffer.from(download.data));
- name: 'Unzip code coverage'
run: unzip rsc-code-coverage.zip

- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
env:
Expand All @@ -48,3 +51,49 @@ jobs:
-Dsonar.pullrequest.key=${{ github.event.workflow_run.pull_requests[0].number }}
-Dsonar.pullrequest.branch=${{ github.event.workflow_run.pull_requests[0].head.ref }}
-Dsonar.pullrequest.base=${{ github.event.workflow_run.pull_requests[0].base.ref }}
- name: Create and Upload Storybook to PR directory
run: |
PR_NUMBER="PR-${{ github.event.workflow_run.pull_requests[0].number }}"
git config user.name "evargast"
git config user.email "[email protected]"
# Fetch the existing gh-pages branch
git fetch origin gh-pages
# Checkout the existing gh-pages branch
git checkout gh-pages
# Remove the PR directory if it exists
rm -rf "${PR_NUMBER}"
# Create the PR directory
mkdir "${PR_NUMBER}"
# Copy the contents of dist-storybook to the directory
cp -r dist-storybook/* "${PR_NUMBER}/"
rm -rf node_modules # Explicitly remove the node_modules directory
rm -rf dist-storybook # Explicitly remove the dist-storybook directory
# Add, commit, and push changes
git add "${PR_NUMBER}/."
git commit -m "Update Storybook for ${PR_NUMBER}"
git push -f origin gh-pages
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Add comment to the PR with Storybook URL
run: |
PR_NUMBER="${{ github.event.workflow_run.pull_requests[0].number }}"
COMMENT_BODY="🎨 Storybook -> https://opensource.adobe.com/react-spectrum-charts/PR-${PR_NUMBER}"
curl -sSL \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-X POST \
-d '{"body":"'"${COMMENT_BODY}"'"}' \
"https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 77877fb

Please sign in to comment.