-
Notifications
You must be signed in to change notification settings - Fork 1
js workflow: shared workflow for javascript builds based on yarn2 #287
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5043340
js workflow: first release
chicco785 6bc0ddc
Update js.yaml
chicco785 fe9ebef
document
chicco785 1d45de1
Automated yaml-lint fixes [dependabot skip]
fa9ed56
fix mispelling
chicco785 b5fc769
Merge branch 'js-workflow-base' of https://github.com/zaphiro-technol…
chicco785 7b004a2
Merge branch 'main' into js-workflow-base
chicco785 b8294c1
docs(release_notes): update RELEASE_NOTES.md [dependabot skip]
cosimomeli 6bb174c
Apply suggestions from code review
chicco785 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,232 @@ | ||
| # Copyright 2024 Zaphiro Technologies | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| name: JS Lint & Test | ||
|
|
||
| concurrency: | ||
| group: ${{github.repository}}-${{ github.ref_name }}-js | ||
| cancel-in-progress: true | ||
|
|
||
| # permissions: | ||
| # id-token: write # This is required for requesting the JWT, which is needed to authenticate with AWS and pull DVC datasets | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| code-scan: | ||
| required: false | ||
| default: true | ||
| type: boolean | ||
| description: False to skip code-scan exec | ||
| vulnerability-scan: | ||
| required: false | ||
| default: true | ||
| type: boolean | ||
| description: False to skip vulnerability-scan exec | ||
| vulnerability-scan-skip-dirs: | ||
| required: false | ||
| default: "vendor,.github" | ||
| type: string | ||
| description: Comma separated list of directories where vulnerability check is skipped | ||
| pull-dvc-datasets: | ||
| required: false | ||
| default: false | ||
| type: boolean | ||
| description: True to install and configure dvc | ||
| repositories: | ||
| required: false | ||
| type: string | ||
| default: "" | ||
| description: Comma or newline-separated list of repositories to grant access to during the JS build. | ||
| jobs: | ||
| changes: | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| files_changed: ${{ steps.filter.outputs.js == 'true' || steps.filter.outputs.scripts == 'true' }} | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 2 # To retrieve the preceding commit. | ||
| - uses: dorny/paths-filter@v4 | ||
| id: filter | ||
| with: | ||
| list-files: shell | ||
| filters: | | ||
| scripts: | ||
| - 'Makefile' | ||
| - '.github/workflows/js.*' | ||
| - '**/*.sql' | ||
| - '.docker/*.yml' | ||
| - '.docker/*.yaml' | ||
| js: | ||
| - '**/*.ts' | ||
| - '**/*.js' | ||
| - '**/*.tsx' | ||
| - '**/*.jsx' | ||
| - 'package.json' | ||
| lint: | ||
| needs: changes | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| if: ${{ needs.changes.outputs.files_changed == 'true' && github.event.pull_request && github.event.pull_request.head.repo.full_name == github.repository }} | ||
| steps: | ||
| - uses: actions/create-github-app-token@v3 | ||
| id: generate-token | ||
| with: | ||
| app-id: ${{ secrets.APP_ID }} | ||
| private-key: ${{ secrets.APP_SECRET }} | ||
| permission-contents: write | ||
| - uses: actions/checkout@v6 | ||
| with: | ||
| ref: ${{github.event.pull_request.head.ref}} # Can't commit on detached PR merge commit, so this checkouts the branch | ||
| token: ${{ steps.generate-token.outputs.token }} | ||
| - run: git config --global "url.https://x-access-token:${{ steps.generate-token.outputs.token }}@github.com/.insteadOf" "https://github.com/" | ||
| - uses: actions/setup-node@v6 | ||
| with: | ||
| node-version-file: package.json | ||
| - name: "Enable Corepack" | ||
| run: corepack enable | ||
| - name: "Install packages" | ||
| run: | | ||
| YARN_ENABLE_SCRIPTS=0 yarn install | ||
| - name: Check types | ||
| run: yarn typecheck | ||
| - name: Lint | ||
| run: | | ||
| yarn fix | ||
| - name: Commit lint changes | ||
| run: | | ||
| git config --global user.name 'Bot' | ||
| git config --global user.email 'bot@zaphiro.ch' | ||
| git commit -am "Automated lint fixes [dependabot skip]" || echo "No changes to commit" | ||
| git push | ||
| test: | ||
| needs: changes | ||
| runs-on: ubuntu-latest | ||
| if: ${{ needs.changes.outputs.files_changed == 'true' }} | ||
| steps: | ||
| - uses: actions/create-github-app-token@v3 | ||
| id: generate-token | ||
| with: | ||
| app-id: ${{ secrets.APP_ID }} | ||
| private-key: ${{ secrets.APP_SECRET }} | ||
| repositories: ${{ github.event.repository.name }}${{ inputs.repositories && format(',{0}', inputs.repositories) || '' }} | ||
| permission-contents: read | ||
| - uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | ||
| - name: Configure AWS Credentials | ||
| if: ${{ inputs.pull-dvc-datasets }} | ||
| id: creds | ||
| uses: aws-actions/configure-aws-credentials@v6 | ||
| with: | ||
| aws-region: eu-south-1 | ||
| role-to-assume: arn:aws:iam::058264335177:role/zaphiro-github-role-demo | ||
| output-credentials: true | ||
| - name: Install DVC | ||
| if: ${{ inputs.pull-dvc-datasets }} | ||
| run: | | ||
| pipx install 'dvc[s3]==3.67.0' | ||
| - name: Set-up git credentials for dvc | ||
| if: ${{ inputs.pull-dvc-datasets }} | ||
| env: | ||
| GH_TOKEN: ${{ steps.generate-token.outputs.token }} | ||
| run: | | ||
| gh auth setup-git | ||
| git config --global credential.helper '!/usr/bin/gh auth git-credential' | ||
| - name: Pull DVC Data | ||
| env: | ||
| GH_TOKEN: ${{ steps.generate-token.outputs.token }} | ||
| if: ${{ inputs.pull-dvc-datasets }} | ||
| run: dvc pull -v --allow-missing | ||
| - run: git config --global "url.https://x-access-token:${{ steps.generate-token.outputs.token }}@github.com/.insteadOf" "https://github.com/" | ||
| - uses: actions/setup-node@v6 | ||
| with: | ||
| node-version-file: package.json | ||
| - name: "Enable Corepack" | ||
| run: corepack enable | ||
| - name: "Install packages" | ||
| run: | | ||
| YARN_ENABLE_SCRIPTS=0 yarn install | ||
| - name: Prepare build | ||
| run: | | ||
| make ci-pre-build | ||
| - name: Login to GitHub Container Registry | ||
| uses: docker/login-action@v4 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Unit tests | ||
| run: make test | ||
| - name: Build | ||
| run: | | ||
| yarn build | ||
| - name: Upload build artifact | ||
| uses: actions/upload-pages-artifact@v5 | ||
| with: | ||
| path: ./build | ||
| - name: SonarCloud Code Scan | ||
| if: ${{ inputs.code-scan }} | ||
| uses: SonarSource/sonarqube-scan-action@v7.1.0 | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | ||
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
| vulnerability: | ||
| needs: changes | ||
| if: ${{ inputs.vulnerability-scan}} | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - name: Run Trivy vulnerability scanner (for summary) | ||
| # trivy-action v0.35.0 (safe version) | ||
| uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 | ||
| with: | ||
| scan-type: fs | ||
| scan-ref: . | ||
| skip-dirs: ${{ inputs.vulnerability-scan-skip-dirs }} | ||
| scanners: "vuln,secret,misconfig" | ||
| hide-progress: true | ||
| output: trivy.txt | ||
| env: | ||
| TRIVY_SKIP_DB_UPDATE: true | ||
| TRIVY_SKIP_JAVA_DB_UPDATE: true | ||
| - name: Publish Trivy Output to Summary | ||
| run: | | ||
| if [[ -s trivy.txt ]]; then | ||
| { | ||
| echo "### Trivy Security Output" | ||
| echo "" | ||
| echo '```text' | ||
| cat trivy.txt | ||
| echo '```' | ||
| } >> $GITHUB_STEP_SUMMARY | ||
| fi | ||
| # this comes as last or scan results won't be uploaded | ||
| - name: Run Trivy vulnerability scanner (security treshold) | ||
| # trivy-action v0.35.0 (safe version) | ||
| uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 | ||
| with: | ||
| scan-type: fs | ||
| scan-ref: . | ||
| skip-dirs: ${{ inputs.vulnerability-scan-skip-dirs }} | ||
| scanners: "vuln,secret,misconfig" | ||
| exit-code: "1" | ||
| severity: MEDIUM,HIGH,CRITICAL | ||
| # On a subsequent call to the action we know trivy is already installed so can skip this | ||
| skip-setup-trivy: true | ||
| env: | ||
| TRIVY_SKIP_DB_UPDATE: true | ||
| TRIVY_SKIP_JAVA_DB_UPDATE: true | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.