How to deploy to github releases from travis - github

I have some repository with a electron-js project. I'm trying to setup build and deploy to github releases from travis CI.
I have next config:
language: node_js
node_js:
- "8"
before_install:
- cd app
install:
- npm install
os:
- linux
- osx
env:
- TARGET_ARCH=x64
script:
- npm run dist
branches:
only:
- master
deploy:
provider: releases
skip_cleanup: true
api_key: $GH_TOKEN
Travis successfully builds app, but didn't upload artifacts to github releases.
As I understood the documentation, It should create a new release with tag untagged-* and upload files to it.
Now I have this messages in build log:
skipped publishing file=Cromberg_1.2.1_amd64.deb reason=existing type
not compatible with publishing type tag=v1.2.1 version=1.2.1
existingType=release publishingType=draft
1.2.1 is a previous tag. What am I doing wrong?
I want to automatically build and creating releases with artifacts on every commit with tags in master branch. But now I just trying to setup deploy on any event.

You need to set the deploy parameters correctly in travis.yml, look this:
language: go
go:
- "1.10"
script:
- CGO_ENABLED=0 go build
- ls
deploy:
provider: releases
api_key: $TOKEN
file: "test"
skip_cleanup: true
on:
tags: false
If you set tags: false, then travis will release your app with untagged tag like this:

To deploy to github releases on tags you should have a part of config like this:
deploy:
provider: releases
skip_cleanup: true
api_key: $GH_TOKEN
file_glob: true
file:
- "dist/Cromberg-*-x86_64.AppImage"
- "dist/Cromberg_*_amd64.deb"
- "dist/Cromberg-*.dmg"
on:
tags: true
Also don't set branches in config like this:
branches:
only:
- master
Because it will build only on this branch and don't use tags (but in deploy config we set tags: true)
Thus, when you make a commit with some tag on master, it will build your app twice: first build on master branch, deploy step will be skipped. Another build on tag, it will create release during this build and upload files to release.

Related

Working directory is not working in my Github action

I'm starting to use Github actions. When I ran the process in my Ubuntu server, one of the config options was to select the work folder, by default, I leave _work. But previously, I had my repository in another folder.
So, I'm trying to add a specific value for working-directory to my yml, file but is not using the value in the build process.
YML File:
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
defaults:
run:
working-directory: /../../../../var/www/mysite.com
jobs:
deployment:
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout#v3
- name: Use Node.js
uses: actions/setup-node#v3
with:
node-version: '14.x'
- name: Install dependencies
run: yarn
- name: Build
run: yarn build
- name: Restart server application
run: pm2 restart pm2_script.json
The process ran ok, but is doing all the process (checkout, build, etc) inside _work and not inside working-directory
What I'm doing wrong?
Thanks!!

How can I prevent my unit test project from being deployed to my Azure Web App along with my ASP.NET Core website project?

I have an ASP .NET Core website whose source code is stored in GitHub. This is automatically deployed to an Azure App Service (running on Linux) when I do a check-in to GitHub. (I set this up a while back using the Azure "wizard", but now I can't find any way to tinker with it).
Recently I added a unit test project to my solution, and when I checked that in the unit test project was deployed along with the web project - which I don't want. (Especially since the runtime host gets confused about which DLL it should run, and decides to run neither - so the website does not start!).
Is there a way to prevent the unit test project from being built or deployed? (I'm happy just to run these tests locally). I'm not even sure where to start - would I do this in GitHub, or in the Azure portal? I can't find any likely-looking knobs or levers either in GitHub or in the Azure portal.
Update: I've found a file that has been created in my repo in a .github/workflows folder. Here's the content:
name: Build and deploy ASP.Net Core app to Azure Web App - MyApp
on:
push:
branches:
- master
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Set up .NET Core
uses: actions/setup-dotnet#v1
with:
dotnet-version: '5.0.x'
include-prerelease: true
- name: Build with dotnet
run: dotnet build --configuration Release
- name: dotnet publish
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
- name: Upload artifact for deployment job
uses: actions/upload-artifact#v2
with:
name: .net-app
path: ${{env.DOTNET_ROOT}}/myapp
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact#v2
with:
name: .net-app
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy#v2
with:
app-name: 'My-App'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_0C864EC866B247EABE271A962BE84378 }}
package: .
While that's progress, I still can't see where I could modify it to prevent it from including the unit test project, because it doesn't actually reference anything directly.
Here's what worked for me:
I changed:
run: dotnet build --configuration Release
...to:
run: dotnet build MyProject --configuration Release
...where MyProject is the name of the folder containing the website project. (dotnet build is run from the solution folder, and the default behavior is that it will build all projects in the solution; specifying a sub-folder name makes it build only the project(s) it finds in that folder - see the documentation here).
Similarly, I changed:
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
to:
run: dotnet publish MyProject -c Release -o ${{env.DOTNET_ROOT}}/myapp
Thanks to #LexLi for pointing me in the right direction.

How to add the build files as an asset to a release in Github?

I have a project based on Node/npm and use commitlint, husky and semantic-release. Whenever I push to the protected main branch I want to create a new release.
In Github I added the following workflow
name: Release on push on main
on:
push:
branches:
- main
jobs:
release-on-push-on-main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node#v2
with:
node-version: 16.x
- name: Install dependencies
run: npm install
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx semantic-release --branches main
which does the job very well. When moving to the releases I see that semantic-release attaches the source code
Running npm run build generates me a dist folder containing all the build files. How can enhance my workflow to add the build to the assets?
Adding the steps
- name: Run build
run: npm run build
- name: Archive build
uses: actions/upload-artifact#v2
with:
name: build
path: dist
before running the Release step seems to work as expected
but how can I add it as an asset to the release?
You need to configure the semantic-release github-plugin
using the configuration file
The CLI uses some default configuration, and if you need a custom config
you will have to create an entire config from scratch (as far as I know).
Create a file called release.config.js in the root project folder:
// make sure you install #semantic-release/github as dev dependency
module.exports = {
"plugins": [
// additional config...
["#semantic-release/github", {
"assets": [
{"path": "dist/asset.min.css", "label": "CSS distribution"},
{"path": "dist/asset.min.js", "label": "JS distribution"}
]
}],
]
}
I can also recommend using an alternative to semantic-release
called atomic-release.
It's an SDK with a strategy to release NPM packages (kind of like semantic-release). Check it out GithubNpmPackageStrategy
Disclaimer: I'm the author of atomic-release.

Could not find a 'develop' or 'master' branch, neither locally nor remotely. - Semantic gitversion

I have a repo in azure and it has the default branch "main".
Also, I have a task in yml file for semantic versioning.
- task: gittools.gitversion.gitversion-task.GitVersion#5
displayName: Get Semantic Git Version
I am hitting the below error
No branch configuration found for branch personal/release1, falling
back to default configuration System.InvalidOperationException: Could
not find a 'develop' or 'master' branch, neither locally nor remotely.
So, I just created a develop branch and triggered build then the semantic version got succeeded.
We do not want to maintain develop or master branch as per guidelines.
How can we overcome the error without maintaining the master and develop branch?
Thanks
Naresh Ede
It looks that this is not supported yet by GitTools\GitVersion and it is still waiting for a solution.
But to overcome this you can provide GitVersion.yml file
mode: ContinuousDelivery
branches:
master:
regex: main
mode: ContinuousDelivery
tag:
increment: Patch
prevent-increment-of-merged-branch-version: true
track-merge-target: false
feature:
regex: feature(s)?[/-]
mode: ContinuousDeployment
develop:
regex: dev(elop)?(ment)?$
mode: ContinuousDeployment
tag: alpha
hotfix:
regex: hotfix(es)?[/-]
mode: ContinuousDeployment
tag: beta
release:
regex: release(s)?[/-]
mode: ContinuousDeployment
tag: rc
ignore:
sha: []
And then use it like this
steps:
- task: GitVersion#5
inputs:
runtime: 'core'
configFilePath: 'GitVersion.yml'
updateAssemblyInfo: true
GitVersion task is deprecated. It uses the an old version(5.0.1) of GitVersion, which caused above error. It is recommended to use GitTools bundle extension instead. You can install GitTools extension in your project. See below example;
- task: gitversion/setup#0
displayName: Install GitVersion
inputs:
versionSpec: '5.x'
- task: gitversion/execute#0
Please check the document for more usages.
You can also use UseGitVersion task. And use the latest 5 version by specifying the versionSpec.
- task: UseGitVersion#5
displayName: gitversion
inputs:
versionSpec: 5.x
enabled: true
Or you can use a GitVersion.yml config file as Krzysztof Madej mentioned to map the main branch to master branch.
mode: ContinuousDelivery
branches:
master:
regex: main
mode: ContinuousDelivery

Can't build github page generic error

I am using travis CI to publish my jekyll site.
Whole repo.
The relevant parts are:
.travis.yml
language: ruby
rvm:
- 2.3.3
before_script:
- chmod +x ./script/cibuild # or do this locally and commit
# Assume bundler is being used, therefore
# the `install` step will run `bundle install` by default.
script: ./script/cibuild
# branch whitelist, only for GitHub Pages
branches:
only:
- gh-pages # test the gh-pages branch
- /pages-(.*)/ # test every branch which starts with "pages-"
env:
global:
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true # speeds up installation of html-proofer
sudo: false # route your build to the container-based infrastructure for a faster build
deploy:
provider: pages
skip-cleanup: true
github-token: $GITHUB_TOKEN # Set in the settings page of your repository, as a secure variable
keep-history: true
on:
branch: gh-pages
My cibuild file is the following:
#!/usr/bin/env bash
set -e # halt script on error
bundle exec jekyll build
This is the full log of the build.
Everything seems to be deploying ok, no errors.
But on Github I get:
The troubleshooting is no help.
Just in case. I'm running jekyll-assets and I can't to build it with gh-pages directly, hence travis, see https://github.com/github/pages-gem/issues/189 specifically: https://github.com/github/pages-gem/issues/189#issuecomment-319070628
I am really not sure how to process, the github error is of no help.
If your site is already built by CI, you can add a .nojekyll file at the root of your code to instruct gh-pages not to generate but just publish you site.