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 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
211a5c7
feat: added action command, versioning
guitarrapc Dec 10, 2024
709e4ca
refactor: move handler
guitarrapc Dec 11, 2024
e04ce40
feat: add UpdateVersion command
guitarrapc Dec 11, 2024
1451152
chore: Validate version
guitarrapc Dec 11, 2024
28b131b
fix: writeBack
guitarrapc Dec 11, 2024
1ad979b
chore: format output
guitarrapc Dec 11, 2024
9962877
ci: change Update files to version to use C# Actions
guitarrapc Dec 11, 2024
e2c3a61
feat: Update package.json to 1.2.313
github-actions[bot] Dec 11, 2024
cb4cbdb
chore: update package, add editorconfig
guitarrapc Dec 17, 2024
3d44e8f
chore: remove unnecessary suggestion
guitarrapc Dec 17, 2024
b42dda7
feat: Update package.json to 1.2.315
github-actions[bot] Dec 17, 2024
854cc09
chore: update test name
guitarrapc Dec 17, 2024
bff2c1b
feat: Update package.json to 1.2.317
github-actions[bot] Dec 17, 2024
e639f10
feat: add ValidateArtifactCommand
guitarrapc Dec 17, 2024
6abba7c
ci: replace Validate package Exists Bash to C#
guitarrapc Dec 17, 2024
dd91016
chore: skip on empty input
guitarrapc Dec 17, 2024
b07f3f2
chore: enable verbose
guitarrapc Dec 17, 2024
66d8d72
chore: skip
guitarrapc Dec 17, 2024
a78cc8a
feat: add ValidateNupkhExists command
guitarrapc Dec 17, 2024
ac59662
ci: change validate nupkg from Bash to C#
guitarrapc Dec 17, 2024
64dd52c
feat: Update package.json to 1.2.327
github-actions[bot] Dec 18, 2024
f68acdc
feat: UpdateVersion to handle git commit
guitarrapc Jan 7, 2025
1ea60aa
fix: add GITHUB_CONTEXT
guitarrapc Jan 7, 2025
2b52822
fix: use git commit -a
github-actions[bot] Jan 7, 2025
3b16c1b
fix: set sha on no change
guitarrapc Jan 7, 2025
419beef
Merge branch 'main' into feature/actions
guitarrapc Jan 7, 2025
9133eab
chore: escape commit message for Linux
guitarrapc Jan 7, 2025
109561e
chore: escape string
guitarrapc Jan 8, 2025
e9783c8
chore: output handling
github-actions[bot] Jan 8, 2025
2251d6b
chore: path
github-actions[bot] Jan 8, 2025
8f35a71
refactor: update
guitarrapc Jan 8, 2025
cf66aba
feat: move validate-tag to zx
guitarrapc Jan 8, 2025
ba44d29
feat: Update package.json to 1.2.351
github-actions[bot] Jan 8, 2025
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
23 changes: 9 additions & 14 deletions .github/workflows/test-update-packagejson.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,21 @@ jobs:
echo -n "FACT: sha for update-packagejson and update-packagejson3 should have same commit id. "
if [[ "${{ needs.update-packagejson.outputs.sha }}" == "${{ needs.update-packagejson3.outputs.sha }}" ]]; then echo "[O PASS]"; else echo "[X FAIL]" && exit 1; fi

echo -n "FACT: is-branch-created for update-packagejson should be created. "
if [[ "${{ needs.update-packagejson.outputs.is-branch-created }}" == "true" ]]; then echo "[O PASS]"; else echo "[X FAIL]" && exit 1; fi
echo -n "FACT: is-branch-created for update-packagejson2 should not be created. "
if [[ "${{ needs.update-packagejson2.outputs.is-branch-created }}" == "false" ]]; then echo "[O PASS]"; else echo "[X FAIL]" && exit 1; fi
echo -n "FACT: is-branch-created for update-packagejson3 should not be created. "
if [[ "${{ needs.update-packagejson3.outputs.is-branch-created }}" == "false" ]]; then echo "[O PASS]"; else echo "[X FAIL]" && exit 1; fi

echo -n "FACT: branch-name for update-packagejson should be expected. "
if [[ "${{ needs.update-packagejson.outputs.branch-name }}" == "test-release/${{ needs.set-tag.outputs.tag }}" ]]; then echo "[O PASS]"; else echo "[X FAIL]" && exit 1; fi
echo -n "FACT: branch-name for update-packagejson2 should be exists. "
if [[ "${{ needs.update-packagejson2.outputs.branch-name }}" == "test-release/${{ needs.set-tag.outputs.tag }}" ]]; then echo "[O PASS]"; else echo "[X FAIL]" && exit 1; fi
echo -n "FACT: branch-name for update-packagejson3 should be exists. "
if [[ "${{ needs.update-packagejson3.outputs.branch-name }}" == "test-release/v${{ needs.set-tag.outputs.tag }}" ]]; then echo "[O PASS]"; else echo "[X FAIL]" && exit 1; fi
echo -n "FACT: branch-name for update-packagejson2 should be empty. "
if [[ "${{ needs.update-packagejson2.outputs.branch-name }}" == "" ]]; then echo "[O PASS]"; else echo "[X FAIL]" && exit 1; fi
echo -n "FACT: branch-name for update-packagejson3 should be empty. "
if [[ "${{ needs.update-packagejson3.outputs.branch-name }}" == "" ]]; then echo "[O PASS]"; else echo "[X FAIL]" && exit 1; fi
env:
HEAD_REF: ${{ github.head_ref }}

cleanup:
if: ${{ needs.update-packagejson3.outputs.is-branch-created == 'true' }}
needs: [update-packagejson3]
if: ${{ needs.update-packagejson.outputs.is-branch-created == 'true' }}
needs: [update-packagejson, update-packagejson3]
uses: ./.github/workflows/clean-packagejson-branch.yaml
with:
branch: ${{ needs.update-packagejson3.outputs.branch-name }}
branch: ${{ needs.update-packagejson.outputs.branch-name }}

actions-timeline:
needs: [set-tag, update-packagejson, update-packagejson2, test]
Expand Down
116 changes: 26 additions & 90 deletions .github/workflows/update-packagejson.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ on:
description: "package.json path to update. You can input multiline paths. Supported files are `package.json`, `plugin.cfg` and `Directory.Build.props`"
required: true
type: string
ref:
description: "checkout ref"
required: false
type: string
default: ''
require-validation:
description: "true require validation must pass, false to keep going even validation failed."
required: false
Expand All @@ -31,21 +36,16 @@ on:
required: false
type: boolean
default: true
ref:
description: "checkout ref"
required: false
type: string
default: ''
outputs:
sha:
description: "Git commit sha after package.json has changed."
value: ${{ jobs.update-packagejson.outputs.sha }}
branch-name:
description: Git branch name created.
value: ${{ jobs.update-packagejson.outputs.branch-name }}
is-branch-created:
description: Indicate is Git branch created or not.
value: ${{ jobs.update-packagejson.outputs.is-branch-created }}
sha:
description: "Git commit sha after package.json has changed."
value: ${{ jobs.update-packagejson.outputs.sha }}

jobs:
validate:
Expand All @@ -60,71 +60,14 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
sha: ${{ steps.commit.outputs.sha }}
branch-name: ${{ steps.configure.outputs.branch-name }}
is-branch-created: ${{ steps.commit.outputs.is-branch-created }}
branch-name: ${{ steps.update.outputs.branch-name }}
is-branch-created: ${{ steps.update.outputs.is-branch-created }}
sha: ${{ steps.update.outputs.sha }}
steps:
- name: Configure Output variables
id: configure
run: |
echo "branch-name=test-release/${{ inputs.tag }}" | tee -a "$GITHUB_OUTPUT"

- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}

# package.json
# "version": 1.2.3 -> "version": 2.0.0
# plugin.cfg
# version="1.2.3" -> version="2.0.0"
#
# 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::"
done <<< "${{ inputs.file-path }}"
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main

# dotnet run
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
Expand All @@ -140,32 +83,25 @@ jobs:
done <<< "${{ inputs.dotnet-run-path }}"
if: ${{ inputs.dotnet-run-path != '' }}

- name: Check update on git
id: check_update
run: git diff --exit-code || echo "changed=1" | tee -a "$GITHUB_OUTPUT"

- name: Commit files (updated? = ${{ steps.check_update.outputs.changed == '1' }})
id: commit
# package.json
# "version": 1.2.3 -> "version": 2.0.0
# plugin.cfg
# version="1.2.3" -> version="2.0.0"
#
# TIPS: Converting file-oath from \n to ,
- name: Update files to version ${{ needs.validate.outputs.normalized_tag }}
id: update
run: |
if [[ "${{ steps.check_update.outputs.changed }}" == "1" ]]; then
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -m "feat: Update package.json to ${{ needs.validate.outputs.normalized_tag }}" -m "Commit by [GitHub Actions](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" -a
echo "sha=$(git rev-parse HEAD)" | tee -a "$GITHUB_OUTPUT"
echo "is-branch-created=${{ inputs.dry-run }}" | tee -a "$GITHUB_OUTPUT"
elif [[ "${{ inputs.ref }}" != "" ]]; then
echo "sha=$(git rev-parse HEAD)" | tee -a "$GITHUB_OUTPUT"
echo "is-branch-created=false" | tee -a "$GITHUB_OUTPUT"
else
echo "sha=" | tee -a "$GITHUB_OUTPUT"
echo "is-branch-created=false" | tee -a "$GITHUB_OUTPUT"
fi
file_path_csv=$(echo "${{ inputs.file-path }}" | tr '\n' ',' | sed 's/,$/\n/')
dotnet run --project "./src/Actions/Actions.csproj" -- update-version --version "${{ needs.validate.outputs.normalized_tag }}" --paths "${file_path_csv}" ${{ inputs.dry-run && '--dry-run' || '' }}
env:
GITHUB_CONTEXT: ${{ toJson(github) }}

- name: Push changes
if: ${{ steps.check_update.outputs.changed == '1' }}
if: ${{ steps.update.outputs.commited == '1' }}
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }} # auto generated token
branch: ${{ inputs.ref }}
branch: ${{ steps.update.outputs.branch-name || inputs.ref }}
tags: false
force: ${{ inputs.dry-run }}
44 changes: 8 additions & 36 deletions .github/workflows/validate-tag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ on:
required: true
type: string
outputs:
normalized_tag:
normalized-tag:
description: normalized tag, tag without v prefix.
value: ${{ jobs.validate.outputs.normalized_tag }}
value: ${{ jobs.validate.outputs.normalized-tag }}
tag:
description: same as input tag
value: ${{ jobs.validate.outputs.tag }}
Expand Down Expand Up @@ -43,43 +43,15 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
tag: ${{ steps.trim.outputs.tag }}
normalized_tag: ${{ steps.trim.outputs.normalized_tag }}
normalized-tag: ${{ steps.validate.outputs.normalized-tag }}
tag: ${{ steps.validate.outputs.tag }}
validated: ${{ steps.validate.outputs.validated }}
steps:
- name: Set version without "v" prefix
id: trim
run: |
input_tag="${{ inputs.tag }}"
if [[ "$input_tag" == v* ]]; then
normalized_tag="${input_tag:1}"
else
normalized_tag="$input_tag"
fi
echo "normalized_tag=$normalized_tag" | tee -a "$GITHUB_OUTPUT"
echo "tag=${{ inputs.tag }}" | tee -a "$GITHUB_OUTPUT"

# Only check released tag, allow override draft and pre-release. Old to new sort by version number.
- name: Validate tag is not reverting
shell: bash
- uses: actions/checkout@v4
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
- name: Validate Tag
id: validate
run: |
release_latest=$(gh release list --exclude-drafts --exclude-pre-releases --json tagName,isLatest | jq -c -r ".[] | select(.isLatest == true) | .tagName")
sorted_latest=$(echo -e "${release_latest}\n${{ steps.trim.outputs.normalized_tag }}" | sort -V | tail -n 1)
if [[ "$release_latest" == "" ]]; then
echo "There is not release tag."
echo "validated=true" | tee -a "$GITHUB_OUTPUT"
elif [[ "$sorted_latest" == "$release_latest" ]]; then
echo "Tag is reverting to old version. Please bump the version. tag: ${{ inputs.tag }} (normalized_tag: ${{ steps.trim.outputs.normalized_tag }}), latest: $release_latest"
echo "validated=false" | tee -a "$GITHUB_OUTPUT"

if [[ "${{ inputs.require-validation }}" == "true" ]]; then
exit 1
fi
else
echo "Great, tag is latest. tag: ${{ inputs.tag }} (normalized_tag: ${{ steps.trim.outputs.normalized_tag }}), latest: $release_latest"
echo "validated=true" | tee -a "$GITHUB_OUTPUT"
fi
run: dotnet run --project "./src/Actions/Actions.csproj" -- validate-tag --tag "${{ inputs.tag }}" ${{ inputs.require-validation && '--require-validation' || '' }}
env:
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Loading