diff --git a/.github/workflows/check_and_commit.yml b/.github/workflows/check_and_commit.yml new file mode 100644 index 000000000..059ce2b6d --- /dev/null +++ b/.github/workflows/check_and_commit.yml @@ -0,0 +1,134 @@ +name: Check and Commit + +on: + workflow_call: + +jobs: + duplicate_samples_and_publish_dependencies: + name: Duplicate Samples And Publish Dependencies + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + projectPath: + - src/UnitySampleProject + testMode: + - PlayMode + - EditMode + steps: + - uses: actions/checkout@v4 + with: + lfs: true + - name: Configure Git + run: | + git config user.email $git_email + git config user.name "${{ github.actor }}" + env: + git_email: "${{ github.actor }}@users.noreply.github.com" + - name: Duplicate Web3 Unity Samples + run: | + export SOURCE_PATH= + export DESTINATION_DIRECTORY= + export DESTINATION_PATH= + + export DUPLICATE_SAMPLE_VARS=${{ vars.DUPLICATE_SAMPLE_VARS }} + + for entry in "${DUPLICATE_SAMPLE_VARS[@]}" + do + IFS=':' read -ra dirs <<< "$entry" + SOURCE_PATH=${dirs[0]} + DESTINATION_DIRECTORY=${dirs[1]} + + SOURCE_PATH="${GITHUB_WORKSPACE}/$SOURCE_PATH/$(ls "$SOURCE_PATH" | head -n 1)/$DESTINATION_DIRECTORY" + + DESTINATION_PATH="${GITHUB_WORKSPACE}/${dirs[2]}" + + rm -rf "$DESTINATION_PATH" + mkdir -p "$DESTINATION_PATH" + cp -r "$SOURCE_PATH/." "$DESTINATION_PATH" + + git add "$DESTINATION_PATH." -f + done + - name: update submodules + # clone submodules + run: | + git submodule update --init + shell: bash + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 6.0.x + - name: Publish Solution DLLs + run: | + dotnet publish src/ChainSafe.Gaming.Unity/ChainSafe.Gaming.Unity.csproj -c Release /property:Unity=true + - name: Move DLLs to Unity Packages + run: | + + export PUBLISH_PATH="${GITHUB_WORKSPACE}/${{ vars.PUBLISH_PATH }}" + + echo -e "DLLs Generated\n$(ls "$PUBLISH_PATH")" + + export PACKAGE_DEPENDENCIES=($(<${GITHUB_WORKSPACE}/scripts/data/published_dependencies.txt)) + + PACKAGE_DEPENDENCIES="${PACKAGE_DEPENDENCIES//$'\n'/ }" + PACKAGE_DEPENDENCIES="${PACKAGE_DEPENDENCIES//$'\r'/}" + + export DLL_META_FILE_TEMPLATE="${{ vars.DLL_META_FILE_TEMPLATE }}" + + for entry in "${PACKAGE_DEPENDENCIES[@]}" + do + IFS=':' read -ra dirs <<< "$entry" + export PACKAGE_LIB_PATH="${GITHUB_WORKSPACE}/${dirs[0]}" + + if [ -d "$PACKAGE_LIB_PATH" ]; then + rm "$PACKAGE_LIB_PATH"*.dll + else + mkdir -p "$PACKAGE_LIB_PATH" + fi + + IFS=';' read -ra dependencies <<< "${dirs[1]}" + + for dependency in "${dependencies[@]}" + do + cp "$PUBLISH_PATH/$dependency.dll" $PACKAGE_LIB_PATH + if ! [ -f "$PACKAGE_LIB_PATH$dependency.dll.meta" ]; then + echo -e "${DLL_META_FILE_TEMPLATE/"[[assetGuid]]"/"$(uuidgen | tr -d '-')"}" >> "$PACKAGE_LIB_PATH$dependency.dll.meta" + fi + done + + git add "$PACKAGE_LIB_PATH." -f + done + - uses: actions/cache@v2 + with: + path: ${{ matrix.projectPath }}/Library + key: Library-${{ matrix.projectPath }} + restore-keys: | + Library- + - uses: game-ci/unity-test-runner@v3 + id: tests + env: + UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} + with: + projectPath: ${{ matrix.projectPath }} + testMode: ${{ matrix.testMode }} + artifactsPath: ${{ matrix.testMode }}-artifacts + githubToken: ${{ secrets.GITHUB_TOKEN }} + checkName: ${{ matrix.testMode }} Test Results + coverageOptions: 'generateAdditionalMetrics;generateHtmlReport;generateBadgeReport;' + - uses: actions/upload-artifact@v3 + if: always() + with: + name: Test results for ${{ matrix.testMode }} + path: ${{ steps.tests.outputs.artifactsPath }} + - uses: actions/upload-artifact@v3 + if: always() + with: + name: Coverage results for ${{ matrix.testMode }} + path: ${{ steps.tests.outputs.coveragePath }} + - name: Commit and Push changes + if: ${{ github.ref_name == 'dev' }} + run: | + git diff-index --cached --quiet HEAD || git commit -m 'Auto Commit + - Duplicate Packages Samples + - Publish DLL Dependencies' + git push \ No newline at end of file diff --git a/.github/workflows/duplicate_samples.yml b/.github/workflows/duplicate_samples.yml deleted file mode 100644 index 065453f78..000000000 --- a/.github/workflows/duplicate_samples.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Duplicate Packages Samples Workflow - -on: - workflow_call: - -jobs: - duplicate: - name: Duplicate samples job 👯 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.ref }} - - name: Duplicate Web3 Unity Samples - run: | - git config user.email $git_email - git config user.name "${{ github.actor }}" - - export SOURCE_PATH= - export DESTINATION_DIRECTORY= - export DESTINATION_PATH= - - export DUPLICATE_SAMPLE_VARS=${{ vars.DUPLICATE_SAMPLE_VARS }} - - for entry in "${DUPLICATE_SAMPLE_VARS[@]}" - do - IFS=':' read -ra dirs <<< "$entry" - SOURCE_PATH=${dirs[0]} - DESTINATION_DIRECTORY=${dirs[1]} - - SOURCE_PATH="${GITHUB_WORKSPACE}/$SOURCE_PATH/$(ls "$SOURCE_PATH" | head -n 1)/$DESTINATION_DIRECTORY" - - DESTINATION_PATH="${GITHUB_WORKSPACE}/${dirs[2]}" - - rm -rf "$DESTINATION_PATH" - mkdir -p "$DESTINATION_PATH" - cp -r "$SOURCE_PATH/." "$DESTINATION_PATH" - - git add "$DESTINATION_PATH." -f - done - - git diff-index --cached --quiet HEAD || git commit -m "Auto-duplicate Packages Samples" - git push - env: - git_email: "${{ github.actor }}@users.noreply.github.com" \ No newline at end of file diff --git a/.github/workflows/post_push_checks_and_commits.yml b/.github/workflows/post_push_checks_and_commits.yml new file mode 100644 index 000000000..7a1371922 --- /dev/null +++ b/.github/workflows/post_push_checks_and_commits.yml @@ -0,0 +1,11 @@ +name: Post Push Checks and Commits + +on: + push: + branches: [ dev ] + +jobs: + check_and_commit: + name: Check and Commit + uses: ChainSafe/web3.unity/.github/workflows/check_and_commit.yaml@main + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/pre_pull_request_auto_commits.yml b/.github/workflows/pre_pull_request_auto_commits.yml deleted file mode 100644 index 0c572377b..000000000 --- a/.github/workflows/pre_pull_request_auto_commits.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: Auto Commits - -on: - pull_request: - branches: [ main ] - -jobs: - duplicate_samples: - name: Duplicate Samples - uses: ChainSafe/web3.unity/.github/workflows/duplicate_samples.yml@main - publish_dependencies: - name: Publish Dependencies - uses: ChainSafe/web3.unity/.github/workflows/publish_dependencies.yml@main - needs: [duplicate_samples] \ No newline at end of file diff --git a/.github/workflows/pre_pull_request_checks.yml b/.github/workflows/pre_pull_request_checks.yml index 9529c9c16..a2a3ee013 100644 --- a/.github/workflows/pre_pull_request_checks.yml +++ b/.github/workflows/pre_pull_request_checks.yml @@ -2,7 +2,9 @@ name: Merge Checks on: pull_request: - branches: [ main ] + branches: + - main + - dev types: - labeled - ready_for_review @@ -12,12 +14,13 @@ jobs: name: Web3 Tests if: ${{ github.event.action == 'ready_for_review' || github.event.label.name == 'ready-to-merge'}} uses: ChainSafe/web3.unity/.github/workflows/test.yaml@main - unity_tests: - name: Unity Tests - uses: ChainSafe/web3.unity/.github/workflows/unity_tests.yml@main - needs: [web3_tests] - secrets: inherit analyze_code: name: Analyze Code uses: ChainSafe/web3.unity/.github/workflows/codeql.yml@main - needs: [unity_tests] \ No newline at end of file + needs: [ web3_tests ] + unity_tests: + name: Unity Tests + if: ${{ github.event.pull_request.head.ref == 'main' }} + uses: ChainSafe/web3.unity/.github/workflows/check_and_commit.yml@main + needs: [ analyze_code ] + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/publish_dependencies.yml b/.github/workflows/publish_dependencies.yml deleted file mode 100644 index da99061bb..000000000 --- a/.github/workflows/publish_dependencies.yml +++ /dev/null @@ -1,72 +0,0 @@ -name: Publish Solution Dependencies - -on: - workflow_call: - -jobs: - publish: - name: Publish Dependency DLLs️ - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.ref }} - lfs: true - - name: update submodules - # clone submodules - run: | - git submodule update --init - shell: bash - - name: Setup .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: 6.0.x - - name: Publish Solution DLLs - run: | - dotnet publish src/ChainSafe.Gaming.Unity/ChainSafe.Gaming.Unity.csproj -c Release /property:Unity=true - - name: Move DLLs to Unity Packages then Commit and Push - run: | - - git config user.email $git_email - git config user.name "${{ github.actor }}" - - export PUBLISH_PATH="${GITHUB_WORKSPACE}/${{ vars.PUBLISH_PATH }}" - - echo -e "DLLs Generated\n$(ls "$PUBLISH_PATH")" - - export PACKAGE_DEPENDENCIES=($(<${GITHUB_WORKSPACE}/scripts/data/published_dependencies.txt)) - - PACKAGE_DEPENDENCIES="${PACKAGE_DEPENDENCIES//$'\n'/ }" - PACKAGE_DEPENDENCIES="${PACKAGE_DEPENDENCIES//$'\r'/}" - - export DLL_META_FILE_TEMPLATE="${{ vars.DLL_META_FILE_TEMPLATE }}" - - for entry in "${PACKAGE_DEPENDENCIES[@]}" - do - IFS=':' read -ra dirs <<< "$entry" - export PACKAGE_LIB_PATH="${GITHUB_WORKSPACE}/${dirs[0]}" - - if [ -d "$PACKAGE_LIB_PATH" ]; then - rm "$PACKAGE_LIB_PATH"*.dll - else - mkdir -p "$PACKAGE_LIB_PATH" - fi - - IFS=';' read -ra dependencies <<< "${dirs[1]}" - - for dependency in "${dependencies[@]}" - do - cp "$PUBLISH_PATH/$dependency.dll" $PACKAGE_LIB_PATH - if ! [ -f "$PACKAGE_LIB_PATH$dependency.dll.meta" ]; then - echo -e "${DLL_META_FILE_TEMPLATE/"[[assetGuid]]"/"$(uuidgen | tr -d '-')"}" >> "$PACKAGE_LIB_PATH$dependency.dll.meta" - fi - done - - git add "$PACKAGE_LIB_PATH." -f - done - - git diff-index --cached --quiet HEAD || git commit -m "Published Solution Dependencies to Package Libraries as DLLs" - git push - env: - git_email: "${{ github.actor }}@users.noreply.github.com" \ No newline at end of file diff --git a/.github/workflows/unity_tests.yml b/.github/workflows/unity_tests.yml deleted file mode 100644 index 9998660eb..000000000 --- a/.github/workflows/unity_tests.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: Test Unity Package Workflow - -on: - workflow_call: - -jobs: - testAllModes: - name: Test Job for Unity Package in ${{ matrix.testMode }} 🕹️ - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - projectPath: - - src/UnitySampleProject - testMode: - - PlayMode - - EditMode - steps: - - uses: actions/checkout@v4 - with: - lfs: true - - uses: actions/cache@v2 - with: - path: ${{ matrix.projectPath }}/Library - key: Library-${{ matrix.projectPath }} - restore-keys: | - Library- - - uses: game-ci/unity-test-runner@v3 - id: tests - env: - UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} - with: - projectPath: ${{ matrix.projectPath }} - testMode: ${{ matrix.testMode }} - artifactsPath: ${{ matrix.testMode }}-artifacts - githubToken: ${{ secrets.GITHUB_TOKEN }} - checkName: ${{ matrix.testMode }} Test Results - coverageOptions: 'generateAdditionalMetrics;generateHtmlReport;generateBadgeReport;' - - uses: actions/upload-artifact@v3 - if: always() - with: - name: Test results for ${{ matrix.testMode }} - path: ${{ steps.tests.outputs.artifactsPath }} - - uses: actions/upload-artifact@v3 - if: always() - with: - name: Coverage results for ${{ matrix.testMode }} - path: ${{ steps.tests.outputs.coveragePath }} \ No newline at end of file diff --git a/CONTRIBUTION.md b/CONTRIBUTION.md index 352c79011..3ca06dca9 100644 --- a/CONTRIBUTION.md +++ b/CONTRIBUTION.md @@ -74,7 +74,7 @@ If you're unsure how you would actually extend Chainsafe's SDK, take a look at t 4. **Write Tests**: Write unit tests for your code and ensure that all existing tests pass. 5. **Commit Changes**: Commit your changes with a descriptive commit message using `git commit -m "Add feature X"`. 6. **Push to Your Fork**: Push your changes to your forked repository with `git push origin my-contribution`. -7. **Submit a Pull Request**: Finally, submit a pull request to the main web3.unity repository. +7. **Submit a Pull Request**: Finally, submit a pull request targeting the `dev` branch of web3.unity repository. ## Reporting Issues diff --git a/Packages/.gitignore b/Packages/.gitignore index 4a12d5262..2b9291d09 100644 --- a/Packages/.gitignore +++ b/Packages/.gitignore @@ -89,5 +89,10 @@ crashlytics-build.properties /io.chainsafe.web3-unity.lootboxes/Chainlink/Runtime/Libraries/*.pdb /io.chainsafe.web3-unity.lootboxes/Chainlink/Runtime/Libraries/*.pdb.meta +/io.chainsafe.web3-unity/Samples~/* +/io.chainsafe.web3-unity.lootboxes/Samples~/* +/io.chainsafe.web3-unity.ramp/Samples~/* +/io.chainsafe.web3-unity.web3auth/Samples~/* + # Since the folder is called 'Debug', it's being ignored, so negate that !/io.chainsafe.web3-unity.web3auth/Runtime/Plugins/Web3AuthSDK/Debug \ No newline at end of file