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

Fix crash with duplicate paths #4896

Merged
merged 5 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
76 changes: 47 additions & 29 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,69 @@
name: "Code scanning - action"
name: "CodeQL"

on:
push:
branches: ["main", "release/*"]
pull_request:
branches: ["main", "release/*"]
schedule:
- cron: "0 19 * * 0"
- cron: "30 3 * * 3"

jobs:
CodeQL-Build:
# CodeQL runs on ubuntu-latest and windows-latest
runs-on: ubuntu-latest
analyze:
name: Analyze
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners
# Consider using larger runners for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: ["javascript-typescript"]
# CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ]
# Use only 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2

# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
# Override language selection by uncommenting this and choosing your languages
# with:
# languages: go, javascript, csharp, python, cpp, java
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

#- run: |
# make bootstrap
# make release
# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"changes": [
{
"packageName": "@autorest/core",
"comment": "Fix: Crash when deduplication paths",
"type": "patch"
},
{
"packageName": "@autorest/core",
"comment": "Fix: Crash reporting zero exit code when a plugin report a crash but send invalid exception",
"type": "patch"
}
],
"packageName": "@autorest/core"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@azure-tools/deduplication",
"comment": "Fix: Crash when deduplication paths",
"type": "patch"
}
],
"packageName": "@azure-tools/deduplication"
}
4 changes: 3 additions & 1 deletion packages/extensions/core/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,9 @@ async function main() {
// - doing the inversion (instanceof Error) doesn't reliably work since that seems to return false on Errors marshalled from safeEval
if (e instanceof Exception) {
logger.log({ level: "error", message: e.message });
exitCode = e.exitCode;
if (e.exitCode) {
Copy link
Member

@mikeharder mikeharder Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timotheeguerin: Can you explain why this check is needed? Might be obvious but I don't see it.

exitCode = e.exitCode;
}
}
if (e !== false) {
logger.log({ level: "error", message: `!${e}` });
Expand Down
5 changes: 2 additions & 3 deletions packages/libs/deduplication/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ export class Deduplicator {
let filename = path[xMsMetadata].filename;
let originalLocations = path[xMsMetadata].originalLocations;
const pathFromMetadata = path[xMsMetadata].path;
let profiles = path[xMsMetadata].profiles;

let profiles = path[xMsMetadata].profiles ?? {};
// extract path properties excluding metadata
const { "x-ms-metadata": metadataCurrent, ...filteredPath } = path;

Expand All @@ -218,7 +217,7 @@ export class Deduplicator {
originalLocations = originalLocations.concat(anotherPath[xMsMetadata].originalLocations);
profiles = getMergedProfilesMetadata(
profiles,
anotherPath[xMsMetadata].profiles,
anotherPath[xMsMetadata].profiles ?? {},
path[xMsMetadata].path,
originalLocations,
);
Expand Down
Loading