diff --git a/.github/workflows/release_ci.yml b/.github/workflows/release_ci.yml new file mode 100644 index 0000000..110ed0e --- /dev/null +++ b/.github/workflows/release_ci.yml @@ -0,0 +1,106 @@ +name: release_ci + +on: + push: # Runs on push to main branch + branches: + - "main" + + schedule: # Runs automatically every Friday at 07:00 EST | 11:00 UTC | 12:00 CET | 16:30 IST + - cron: "0 11 * * 5" + + workflow_dispatch: # Runs when manually triggered + +jobs: + + pre-build: # Performs some simple checks before building the plugin(s) + name: Pre Build + runs-on: ubuntu-latest + outputs: + any_changed: ${{steps.changed-files.outputs.any_changed}} + version: ${{steps.set_version.outputs.version}} + steps: + # Access the files of this repo in Actions environment + - name: Checkout Repo + uses: actions/checkout@v3.3.0 + with: + fetch-depth: 0 + + # Check if the project file (containing the version number) was changed + - name: Changed Files + uses: tj-actions/changed-files@v35.5.6 + id: changed-files + with: + files: src/brain_ghplugin.csproj + + # Stop workflow if project file was unchanged + - name: Fail Job + if: ${{steps.changed-files.outputs.any_changed == 'false'}} + run: | + echo "::error title=❌ No Version Update::No changes in version tag was detected" + echo No change in version detected. + echo Exiting workflow. + exit 1 + + # Proceed installing Python (oops!) + - name: Install Python + if: ${{steps.changed-files.outputs.any_changed == 'true'}} + uses: actions/setup-python@v4 + with: + python-version: '3.9' + + # Extract new version number from project file + - name: Update Version + run: python .github/workflows/update_version.py + + # Output version number in environment for later use + - name: Set Version + id: set_version + run: | + echo VersionInfo: ${{ env.VERSION }} + echo PackageName: brain_ghplugin-v${{ env.VERSION }} + echo "version=${{ env.VERSION }}" >> "$GITHUB_OUTPUT" + + build: # Builds the Visual Studio solution using MsBuild + name: Build GH Plugin + runs-on: windows-latest + permissions: + contents: write + needs: [pre-build] # Runs only if pre-build was successful + + steps: + # Access the files of this repo in Actions environment + - name: Checkout Repo + uses: actions/checkout@v3.3.0 + + # Set up MsBuild, and Restore dependencies from NuGet + - name: Setup MsBuild + uses: microsoft/setup-msbuild@v1 + + - name: Setup NuGet + uses: NuGet/setup-nuget@v1 + + - name: Restore NuGet Packages + run: nuget restore src/brain_ghplugin.sln + + # Build the solution + - name: Build Solution + run: msbuild src/brain_ghplugin.sln /p:Configuration=Release + + # Create a ZIP with solution binaries (a.k.a the plugin) + - name: Create Archive + uses: TheDoctor0/zip-release@0.7.1 + with: + type: 'zip' + directory: src/bin/Release/net48/ + filename: brain_ghplugin-v${{ needs.pre-build.outputs.version }}.zip + + # Automatically deploy a new release based on project version number + - name: Deploy Release + uses: ncipollo/release-action@v1.12.0 + with: + name: brain_ghplugin-v${{ needs.pre-build.outputs.version }} # Version number extracted in pre-build + tag: v${{ needs.pre-build.outputs.version }} + artifacts: src/bin/Release/net48/brain_ghplugin-v${{ needs.pre-build.outputs.version }}.zip + makeLatest: true + allowUpdates: false + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/update_version.py b/.github/workflows/update_version.py new file mode 100644 index 0000000..52e94fa --- /dev/null +++ b/.github/workflows/update_version.py @@ -0,0 +1,22 @@ +# - - - - BUILT-IN IMPORTS +import os, re + +# - - - - GLOBALS +env = os.getenv("GITHUB_ENV") +root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +solution_file = os.path.join(root, "src", "brain_ghplugin.csproj") + +# Read version from solution +data = "" +with open(solution_file, 'rt') as file: + data = file.read() +result = re.findall(r"(.*)", data) + +# Add Version info to Environment File +if result is not None: + version = result[0] + with open(env, "a") as file: + file.write(f"VERSION={version}") +else: + print("No Version Match was found") + exit(1) diff --git a/src/Properties/launchSettings.json b/src/Properties/launchSettings.json new file mode 100644 index 0000000..93bcf4c --- /dev/null +++ b/src/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "brain_ghplugin": { + "commandName": "Project", + "commandLineArgs": "/nosplash /runscript=\"_-Grasshopper Banner Disable Window Load Window Show _Enter\"" + } + } +} \ No newline at end of file diff --git a/src/brain_ghplugin.csproj b/src/brain_ghplugin.csproj index b8f9b11..e42e8e0 100644 --- a/src/brain_ghplugin.csproj +++ b/src/brain_ghplugin.csproj @@ -21,5 +21,8 @@ Program - + + + + \ No newline at end of file