-
-
Notifications
You must be signed in to change notification settings - Fork 742
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
Helpers for GitHub Actions #2609
Comments
Agreed, this would be something we would want to support. |
@xt0rted do you have any examples of projects which you are porting to GitHub Actions CI/CD? |
@gep13 I don't have any public .net projects right now, but I could setup a test one if you'd like. Here's the workflows for a node action I'm migrating along with the build output. This is one of my master branch workflows that's building, packaging, and publishing to azure app services. It's being published as s self-contained app so it's using the Windows VM but it could also use Ubuntu or OSX. name: master
on:
push:
branches: master
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout repo
uses: actions/checkout@master
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
version: 3.0.100-preview8-013656
- name: Build Site
run: dotnet build --configuration Release
- name: Publish Site To Artifacts Folder
env:
DOTNET_CONFIGURE_AZURE: 1
run: dotnet publish --configuration Release --output artifacts
- name: Package Artifacts
run: Compress-Archive -Path artifacts\* -DestinationPath artifacts
shell: powershell
- name: Publish Artifacts
uses: actions/upload-artifact@v1
with:
name: artifacts.zip
path: artifacts.zip
- name: Publish To Azure
uses: azure/appservice-actions/webapp@master
with:
app-name: app-name
package: artifacts.zip
publish-profile: ${{ secrets.azureWebAppPublishProfile }} |
@xt0rted thanks for that! An example would be good. I am just curious about "how" Cake is being used in the wild with regard to GitHub Actions CI/CD, to better understand how we can support it, i.e. where it makes sense to get involved, what we leave up to the consumer, etc. |
Guess anything after dotnet tool install -g Cake.Tool
dotnet cake which we probably could provide a GitHub action for that would work xplat. |
@gep13 I'll be moving projects from both AppVeyor and Azure DevOps. In those builds I'm using the following: var buildNumber = EnvironmentVariable<int>("BUILD_BUILDID", 0);
var prNumber = EnvironmentVariable<int>("SYSTEM_PULLREQUEST_PULLREQUESTNUMBER", 0);
Task("PatchAssemblyInfo")
.WithCriteria(TFBuild.IsRunningOnAzurePipelinesHosted)
.Does(() => { ... }); var buildNumber = EnvironmentVariable<int>("APPVEYOR_BUILD_NUMBER", 0);
var prNumber = EnvironmentVariable("APPVEYOR_PULL_REQUEST_NUMBER");
if (AppVeyor.IsRunningOnAppVeyor)
{
AppVeyor.UpdateBuildVersion(version);
}
Information($"Build version: {version}");
Information($"Version suffix: {versionSuffix}"); The main thing I was thinking about carrying over was a check to see if you're running in an action, along with the other environment variables where appropriate. You can also access the full json payload that triggered the workflow by reading the file from the I don't think actions themselves are really relevant to Cake, they're just another build platform to surface information from. You can run scripts as job steps now so to call your build script it's as simple as: steps:
- name: Build Project
run: ./build.ps1
shell: powershell
- name: Build Project
run: ./build.sh
shell: bash If an action uses a Docker container then it always runs on Linux regardless of the host OS, so I don't think there's need for a Cake action like the DevOps task. Maybe a Javascript based action could work but when you can call the script so easily it seems like a lot of work for little gain. |
This is sort of what I was getting at. i.e. does it make sense to have a |
I toyed with a Cake Action in the first release of GitHub Actions, that used the Docker Image that we have for Cake, so you could run that directly, rather than having to do any other bootstrapping, as it was already there. If we continued with that, we would need to update it to the new format, but again, trying to understand "how" we should be involved, and what we should leave up to the creator of the workflow. |
A Later this week I'll be migrating my first cake based project over to actions. Once that's done I'll have a better idea of how the out of the box experience is. |
V2 Has changed actions quite a bit, need to play with it more, but from perf perspective using the global tool could make more sense for some scenarios. And container in others. So we should probably do both.
|
Here's a quick demo using actions to build a .net core site using cake and pushing it to azure app services. https://github.com/xt0rted/actions-cake-demo There's two workflows:
This is the run that did the deploy https://github.com/xt0rted/actions-cake-demo/runs/206324261 The site is using .net core 3.0 preview 8 and is being built on a windows vm targeting |
@xt0rted this is very cool, thanks for sharing! Would be interesting to see if you could do a "staged" deployment. i.e. run the build and generate the artifact, then at some point in the future, use the same artifact to deploy the site, rather than having to run all the build steps again. |
FWIW, I've ported all my Cake related projects to build with both Azure Pipelines and GitHub Actions. Cake.Dungeon builds on Linux, Mac, Windows, and Docker, and dumps all environment variables, which helps verify expected values when putting together a build provider: I also refactored the Azure Pipelines config to match with the GitHub Actions config so you can clearly see the heritage: I hit one issue though; |
If anyone is looking for a GitHub Action for Cake, there's one right over here. 🙂 |
We also need a build provider. See #2678. 😉 |
@soroshsabz there's a build provider available now, so commands could be added to it. |
@devlead thanks for response, did you can add some example or documents in https://cakebuild.net/dsl/ |
Sure documented under GitHubActions.IsRunningOnGitHubActions many of the properties on i.e. GitHubActionsEnvironmentInfo have code samples in the documentation. |
@devlead Ok, thanks a lot for awesome helping, but I couldn't find something like I think |
Correct that's why I wrote commands that could be added to it. So currently it's up for grabs. |
thanks a lot, another point is I think it is good to provide official GitHub Action instead of https://github.com/marketplace/actions/cake-action |
@soroshsabz The cake-action is currently being used to build Cake itself. What would you like to see in an "official" GitHub Action that's not already there? |
📢 The cake-action is now officially part of the Cake organization. |
If no one else is working on this, I'll gladly take it on. |
@ecampidoglio I've assigned issue to you. |
I am trying to use
Is there any documentation/example on how to set up the token so i can use this from cake frosting? |
@jasells You'll need to use Cake action to access GitHub APIs. Until cake-build/cake-action#43 is resolved you'll need to create a minimal Cake script bootstrapper. I've created an example of that here: https://github.com/devlead/BootstrapFrostingAction |
Ahhh, I see. TY for the example, I had also been wondering how to specify the target task. Just for clarity of anyone else reading this, make sure to check the build.yml file here for the key portion of the bootstrapper in the example. Note the explicit task target arg, and that it runs after the "Default" task. |
Now that GitHub Actions supports CI/CD it'd be nice to have some helpers to detect if you're running in an actions workflow like we have for other providers.
There's a list of environment variables that are set so it should be pretty straight forward to do the check and surface the basic info. https://help.github.com/en/articles/virtual-environments-for-github-actions#default-environment-variables
I'm not sure if we'll be able to setup helpers to upload artifacts (for now). There's an action for this but it seems like it references something installed on the VM instead of calling an api endpoint or writing to the log. https://github.com/actions/upload-artifact
Log messages can also be adjusted by prefixing them with
##[debug]
,##[warning]
, and##[error]
. This will highlight them in the build output. There's no docs on this yet, but you can see how it's done in these two files https://github.com/actions/toolkit/tree/master/packages/core/src.Similar to VS Code there's also support for problem matchers, so if we wanted to highlight specific lines from cake's output we could do that by bundling those files alongside cake and registering them if we're in an actions workflow. This could be useful for highlighting the version of cake being used, or any warnings it may give about mismatched versions.
I'm slowly migrating all of my builds over to actions so I'm happy to help add this in and test it.
The text was updated successfully, but these errors were encountered: