-
Notifications
You must be signed in to change notification settings - Fork 9
[added] build workflow #2
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
Draft
thekaushikls
wants to merge
3
commits into
ParametricCamp:main
Choose a base branch
from
thekaushikls:cicd
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"<Version>(.*)</Version>", 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "profiles": { | ||
| "brain_ghplugin": { | ||
| "commandName": "Project", | ||
| "commandLineArgs": "/nosplash /runscript=\"_-Grasshopper Banner Disable Window Load Window Show _Enter\"" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of running this on all push and schedule, it's probably better to run only when a new release is specified:
this would also allow for changes to the version number during dev without accidentally creating a release.
this would also minimize action and minute usages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lin-ycv thanks for the suggestion. I was assuming the
mainbranch will be protected, and contributors will only raise pull request. Which means, only admins can trigger this workflow.Also, since the version information is taken from the
.csprojfile, it would be easier to just update the version number directly from VisualStudio.If you suggest that it is comfortable to update in all places (
Brain.csprojand the GitHub release tag), it can be done. In that case, do you think having aworkflow_dispatchis better? (Example Below)Reference: basecamp
