Skip to content

Commit 5b9bb3f

Browse files
committed
chore: simplify sonar workflow, main workflow build the website if something changed
1 parent ec9445f commit 5b9bb3f

File tree

2 files changed

+46
-79
lines changed

2 files changed

+46
-79
lines changed

.github/workflows/main.yml

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,38 @@ on:
66
pull_request:
77
types: [opened, synchronize, reopened]
88
jobs:
9-
pr:
10-
name: Save PR Info
9+
build-website:
1110
permissions:
12-
contents: none
11+
contents: read
1312
runs-on: ubuntu-latest
1413
steps:
15-
- name: Save PR number to file
16-
if: github.event_name == 'pull_request'
17-
run: echo ${{ github.event.number }} > PR_NUMBER.txt
18-
- name: Archive PR number
19-
if: github.event_name == 'pull_request'
20-
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
14+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
2115
with:
22-
name: PR_NUMBER
23-
path: PR_NUMBER.txt
16+
persist-credentials: false
17+
18+
- name: Get all changed website files
19+
id: changed_website_files
20+
uses: tj-actions/changed-files@e0021407031f5be11a464abee9a0776171c79891 # v47.0.1
21+
with:
22+
files: website/**
23+
24+
- name: Set up Node.js
25+
if: steps.changed_website_files.outputs.any_changed == 'true'
26+
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
27+
with:
28+
node-version: 24.x
29+
30+
- name: Install Yarn
31+
if: steps.changed_website_files.outputs.any_changed == 'true'
32+
working-directory: cli
33+
run: |
34+
corepack enable
35+
corepack prepare yarn@stable --activate
36+
37+
- name: Build Website
38+
if: steps.changed_website_files.outputs.any_changed == 'true'
39+
working-directory: website
40+
run: |
41+
yarn install --immutable
42+
yarn build
43+
yarn compile

.github/workflows/sonar.yml

Lines changed: 15 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,28 @@
11
name: Sonar
22
on:
3-
workflow_run:
4-
workflows: [Build]
5-
types: [completed]
3+
push:
4+
branches:
5+
- master
66
jobs:
77
sonar:
88
name: Sonar
99
permissions:
10-
pull-requests: read
10+
contents: read
1111
runs-on: ubuntu-latest
12-
if: github.repository == 'EclipseFdn/open-vsx.org' && github.event.workflow_run.conclusion == 'success'
12+
if: github.repository == 'EclipseFdn/open-vsx.org'
1313
steps:
14-
- name: Create artifacts directory
15-
run: mkdir -p ${{ runner.temp }}/artifacts
16-
- name: Download PR number artifact
17-
if: github.event.workflow_run.event == 'pull_request'
18-
uses: dawidd6/action-download-artifact@0bd50d53a6d7fb5cb921e607957e9cc12b4ce392 # v12
14+
- name: Checkout
15+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
1916
with:
20-
workflow: Build
21-
run_id: ${{ github.event.workflow_run.id }}
22-
path: ${{ runner.temp }}/artifacts
23-
name: PR_NUMBER
24-
- name: Read PR_NUMBER.txt
25-
if: github.event.workflow_run.event == 'pull_request'
26-
id: pr_number
27-
uses: juliangruber/read-file-action@b549046febe0fe86f8cb4f93c24e284433f9ab58 # v1.1.7
28-
with:
29-
path: ${{ runner.temp }}/artifacts/PR_NUMBER.txt
30-
- name: Request GitHub API for PR data
31-
if: github.event.workflow_run.event == 'pull_request'
32-
uses: octokit/request-action@dad4362715b7fb2ddedf9772c8670824af564f0d # v2.4.0
33-
id: get_pr_data
34-
with:
35-
route: GET /repos/{full_name}/pulls/{number}
36-
number: ${{ steps.pr_number.outputs.content }}
37-
full_name: ${{ github.event.repository.full_name }}
38-
env:
39-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40-
- name: Checkout head branch
41-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
42-
with:
43-
repository: ${{ github.event.workflow_run.head_repository.full_name }}
44-
ref: ${{ github.event.workflow_run.head_branch }}
45-
fetch-depth: 0
4617
persist-credentials: false
47-
- name: Checkout head branch of pull_request
48-
if: github.event.workflow_run.event == 'pull_request'
49-
env:
50-
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
51-
CLONE_URL: ${{ github.event.repository.clone_url }}
52-
run: |
53-
BASE_REF="${{ fromJson(steps.get_pr_data.outputs.data).base.ref }}"
54-
55-
git remote add upstream ${CLONE_URL}
56-
git fetch upstream
57-
git checkout -B ${BASE_REF} upstream/${BASE_REF}
58-
git checkout ${HEAD_BRANCH}
59-
git clean -ffdx && git reset --hard HEAD
60-
- name: SonarCloud Scan on PR
61-
if: github.event.workflow_run.event == 'pull_request'
62-
uses: SonarSource/sonarqube-scan-action@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9 # v7.0.0
63-
env:
64-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
18+
fetch-depth: 0
19+
- name: Cache SonarCloud packages
20+
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
6621
with:
67-
args: >
68-
-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }}
69-
-Dsonar.pullrequest.key=${{ fromJson(steps.get_pr_data.outputs.data).number }}
70-
-Dsonar.pullrequest.branch=${{ fromJson(steps.get_pr_data.outputs.data).head.ref }}
71-
-Dsonar.pullrequest.base=${{ fromJson(steps.get_pr_data.outputs.data).base.ref }}
72-
- name: SonarCloud Scan on push
73-
if: github.event.workflow_run.event == 'push' && github.event.workflow_run.head_repository.full_name == github.event.repository.full_name
74-
uses: SonarSource/sonarqube-scan-action@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9 # v7.0.0
22+
path: ~/.sonar/cache
23+
key: ${{ runner.os }}-sonar
24+
restore-keys: ${{ runner.os }}-sonar
25+
- name: SonarCloud Scan
26+
uses: SonarSource/sonarqube-scan-action@a31c9398be7ace6bbfaf30c0bd5d415f843d45e9 # v7.0.0
7527
env:
76-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7728
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
78-
with:
79-
args: >
80-
-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }}
81-
-Dsonar.branch.name=${{ github.event.workflow_run.head_branch }}

0 commit comments

Comments
 (0)