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

feat: replace Bash to C# Batch #96

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
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
65 changes: 62 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,70 @@ indent_style = space
indent_size = 2
end_of_line = lf

[{appsettings.json,appsettings.*.json}]
[*.cs]
charset = utf-8-bom
indent_style = space
indent_size = 4

[*.cs]
[*.{csproj,props}]
charset = utf-8
indent_style = space
indent_size = 4
indent_size = 2

[{appsettings.json,appsettings.*.json}]
charset = utf-8-bom
indent_style = space
indent_size = 2

[*.cs]
# C# Standards
dotnet_diagnostic.CS1998.severity = none # This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

# Nullable Reference Types
dotnet_diagnostic.CS8618.severity = error # Non-nullable field is uninitialized. Consider declaring as nullable.
dotnet_diagnostic.CS8604.severity = error # Possible null reference argument.
dotnet_diagnostic.CS8629.severity = error # Nullable value type may be null.
dotnet_diagnostic.CS8600.severity = error # Converting null literal or possible null value to non-nullable type.
dotnet_diagnostic.CS8603.severity = error # Possible null reference return.
dotnet_diagnostic.CS8610.severity = error # Nullability of reference types in type of parameter doesn't match overridden member.
dotnet_diagnostic.CS8625.severity = error # Cannot convert null literal to non-nullable reference type.
dotnet_diagnostic.CS8606.severity = error # Possible null reference assignment to iteration variable
dotnet_diagnostic.CS8602.severity = error # Dereference of a possibly null reference.
dotnet_diagnostic.CS8601.severity = error # Possible null reference assignment.
dotnet_diagnostic.CS8614.severity = error # Nullability of reference types in type of parameter doesn't match implicitly implemented member.
dotnet_diagnostic.CS8765.severity = error # Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).
dotnet_diagnostic.CS8619.severity = error # Nullability of reference types in value of type 'GenericType<T?>' doesn't match target type 'GenericType<T>'.

# =================
# Analyzer Rulesets
# =================

# Microsoft.CodeAnalysis.BannedApiAnalyzers
dotnet_diagnostic.RS0030.severity = error # RS0030: Banned API

# Microsoft.VisualStudio.Threading.Analyzers
dotnet_diagnostic.VSTHRD100.severity = error # VSTHRD100: Avoid async void methods
dotnet_diagnostic.VSTHRD101.severity = error # VSTHRD101: Avoid unsupported async delegates
dotnet_diagnostic.VSTHRD110.severity = error # VSTHRD110: Observe result of async calls
dotnet_diagnostic.VSTHRD003.severity = none # VSTHRD003 Avoid awaiting foreign Tasks

# =================
# Format Rulesets
# =================

# IDE0160: Convert to file-scoped namespace
csharp_style_namespace_declarations = file_scoped:warning

# Microsoft.Analyzers.ManagedCodeAnalysis
dotnet_diagnostic.CA2200.severity = error # Rethrow to preserve stack details

# =================
# Too Match Detail Rulesets
# =================

# CONSIDER: Are IDE0051 and IDE0052 too noisy to be warnings for IDE editing scenarios? Should they be made build-only warnings?
dotnet_diagnostic.IDE0005.severity = warning # Remove unnecessary imports
dotnet_diagnostic.IDE0051.severity = warning # Remove unused private member
dotnet_diagnostic.IDE0052.severity = warning # Remove unread private member
dotnet_diagnostic.IDE0079.severity = none # Remove unnecessary suppression
dotnet_diagnostic.IDE0090.severity = none # Simplify new expression
30 changes: 2 additions & 28 deletions .github/workflows/create-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,39 +136,13 @@ jobs:
if: ${{ inputs.release-upload }}
run: |
while read -r asset_path; do
if [[ "${asset_path}" == "" ]]; then continue; fi
# is it a wildcard?
# shellcheck disable=SC2086
if [[ "$asset_path" == *\** || "$asset_path" == *\?* ]]; then
# shellcheck disable=SC2086
if ! ls -l ${asset_path}; then
echo "Specified nuget package not found. path: $asset_path"
if [[ "${asset_path}" == *.nupkg ]]; then
echo ".nupkg must be included in the artifact."
exit 1
fi
fi
continue
fi
# is it a file?
if [[ ! -f "${asset_path}" ]]; then
echo "Specified asset not found. path: ${asset_path}"
exit 1
fi
dotnet run --project "./src/Actions/Actions.csproj" -- validate-file-exists --path-pattern "$asset_path"
done <<< "${{ inputs.release-asset-path }}"
- name: Validate package exists in artifact - NuGet
if: ${{ inputs.nuget-push }}
run: |
while read -r nuget_path; do
if [[ "${nuget_path}" == "" ]]; then continue; fi
# shellcheck disable=SC2086
if ! ls -l ${nuget_path}; then
echo "Specified nuget package not found. path: $nuget_path"
if [[ "${nuget_path}" == *.nupkg ]]; then
echo ".nupkg must be included in the artifact."
exit 1
fi
fi
dotnet run --project "./src/Actions/Actions.csproj" -- validate-nupkg-exists --path-pattern "$nuget_path"
done <<< "${{ inputs.nuget-path }}"

# Create Releases
Expand Down
44 changes: 2 additions & 42 deletions .github/workflows/update-packagejson.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ jobs:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main

# package.json
# "version": 1.2.3 -> "version": 2.0.0
Expand All @@ -81,49 +82,8 @@ jobs:
# TIPS: `grep -v "^$"` is used to remove empty line.
- name: Update files to version ${{ needs.validate.outputs.normalized_tag }}
run: |
expected="${{ needs.validate.outputs.normalized_tag }}"
while read -r file_path; do
if [[ "$file_path" == "" ]]; then continue; fi

echo "Start $file_path"
file_name=$(basename "$file_path")

echo "::group::Before"
cat "$file_path"
echo "::endgroup::"

echo "::group::Updating"
if [[ "${file_name}" == "package.json" ]]; then
# Unity `"version": "VersionString",`
sed -i -e "s/\(\"version\":\) \"\(.*\)\",/\1 \"${{ needs.validate.outputs.normalized_tag }}\",/" "${file_path}"
actual=$(grep "version" "$file_path" | cut -d ':' -f 2 | tr -d ',' | tr -d '"' | tr -d ' ')
elif [[ "${file_name}" == "plugin.cfg" ]]; then
# Godot `version="VersionString"`
sed -i -e "s/\(version=\)\"\(.*\)\"/\1\"${{ needs.validate.outputs.normalized_tag }}\"/" "${file_path}"
actual=$(grep "version=" "$file_path" | cut -d '=' -f 2 | tr -d '"')
elif [[ "${file_name}" == "Directory.Build.props" ]]; then
# .NET `<VersionPrefix>VersionString</VersionPrefix>`
sed -i -e 's|<VersionPrefix>.*</VersionPrefix>|<VersionPrefix>${{ needs.validate.outputs.normalized_tag }}</VersionPrefix>|g' "${file_path}"
# -P is for perl regex, only available in GNU grep
actual=$(grep -oP '<VersionPrefix>\K.*(?=</VersionPrefix>)' "$file_path")
else
echo "Unknown file name ${file_name} is specified."
exit 1
fi
echo "::endgroup::"

echo "::group::After"
cat "$file_path"
echo "::endgroup::"

echo "::group::Validate Change"
if [[ "$actual" != "$expected" ]]; then
echo "Failed. Path: $file_path, Expected: $expected, Actual: $actual"
exit 1
else
echo "Success. Path: $file_path, Expected: $expected, Actual: $actual"
fi
echo "::endgroup::"
dotnet run --project "./src/Actions/Actions.csproj" -- update-version --version "${{ needs.validate.outputs.normalized_tag }}" --path "$file_path"
done <<< "${{ inputs.file-path }}"

# dotnet run
Expand Down
Loading