Is there a way to configure Travis GitHub Pages Deployment within stages? - github

Expected
To be able to deploy Pages to GitHub within Travis using stages.
Result
Fail, I must not have the proper synthax or it is not possible.
Reproduction
Source:
https://docs.travis-ci.com/user/deployment/pages/
https://docs.travis-ci.com/user/build-stages/
Project:
https://travis-ci.org/kopax/deleteme
https://github.com/kopax/deleteme
This work for building the page without stages: See the passing travis job : travis-ci.org/kopax/deleteme/builds/380660202:
dist: trusty
# Blocklist
branches:
except:
- gh-pages # will be deployed to, no need to build it
cache:
directories:
- node_modules
node_js:
- "10"
before_install:
- npm install -g npm
# const
- export PACKAGE_NAME=$(node -p "require('./package.json').name")
- export PACKAGE_VERSION=$(node -p "require('./package.json').version")
- export NODE_VERSION=$(node --version)
- export NPM_VERSION=$(npm --version)
# logging
- npm --version || echo npm not installed
- node --version|| echo node not installed
- npx rollup-umd-scripts --version || echo npx not installed
- echo "package version $PACKAGE_VERSION"
language: node_js
sudo: required
script:
# execute all of the commands which need to be executed
# before running actual tests
- npm run styleguide:build
deploy:
provider: pages
skip_cleanup: true
github_token: $GH_TOKEN # Set in the settings page of your repository, as a secure variable
keep_history: true
local_dir: public/
on:
branch: master
But this is failing when added the Page deployement as a stage See this failed travis job: travis-ci.org/kopax/deleteme/jobs/380983577:
language: node_js
sudo: required
#env:
# global:
# - DISPLAY=:99.0
# - NODE_ENV=test
dist: trusty
# Blocklist
branches:
except:
- gh-pages # will be deployed to, no need to build it
cache:
directories:
- node_modules
node_js:
- "10"
before_install:
- npm install -g npm
# const
- export PACKAGE_NAME=$(node -p "require('./package.json').name")
- export PACKAGE_VERSION=$(node -p "require('./package.json').version")
- export NODE_VERSION=$(node --version)
- export NPM_VERSION=$(npm --version)
# logging
- npm --version || echo npm not installed
- node --version|| echo node not installed
- npx rollup-umd-scripts --version || echo npx not installed
- echo "package version $PACKAGE_VERSION"
stages:
- build
- test
- release
- deploy
script:
# execute all of the commands which need to be executed
# before running actual tests
- npm run styleguide:build
jobs:
include:
# Job: Build
- stage: build
node_js:
- lts/*
# - 10
# - 8
script:
- npm run build
branches:
only:
- release
- dev
- master
# Job: Test
- stage: test
node_js:
- lts/*
# - 10
# - 8
script:
- npm run test
branches:
only:
- release
- dev
- master
# Job: Release
- stage: release
node_js:
- lts/*
skip_cleanup: true
script:
- npx semantic-release
branches:
only:
- master
# Job: Page
- stage: deploy
provider: pages
skip_cleanup: true
github_token: $GH_TOKEN # Set in the settings page of your repository, as a secure variable
keep_history: true
local_dir: public/
on:
branch: master
Does anybody know how I can have stages deployment with page working in Travis?

Your deploy stage had no install/script defined, thus it took default one.
You need to define in stage what you want to do, you forgot about deploy level.
To have dedicated stage for deployment only, configure it like this:
- stage: deploy
if: type = push AND branch = master # or whenever you want to deploy
script: skip # to not run Travis' default script
deploy: # <-- that was missing !!!
- provider: pages
skip_cleanup: true
github_token: $GH_TOKEN # Set in the settings page of your repository, as a secure variable
keep_history: true
local_dir: public/

Related

Github Action error every step must define a `uses` or `run` key

I couldn't make this workflow work, I'm always receiving this error every step must define a "uses" or "run" key, but looking at my script I don't see any issues, can someone pls help me fix this? It does not seem like a - problem as it usually is.
# This is a basic workflow to help you get started with Actions
name: Build Digital Ocean Image
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "master" branch
push:
branches:
- '*'
- '*/*'
- '**'
- '!master'
pull_request:
branches: [ "master" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
packages:
runs-on: ubuntu-latest
steps:
- name: Install packages
run: |
apt-get install curl -y
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt-get update && sudo apt-get install packer
apt-get install ansible -y
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
# runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout
uses: actions/checkout#v3
# Runs a single command using the runners shell
- name: Packer init
env:
DIGITALOCEAN_TOKEN=${{ secrets.DIGITALOCEAN_TOKEN }}
run: packer init
working-directory: /home/runner/work/packer-do-custom-images/demo
# Runs a set of commands using the runners shell
- name: Packer build
run: packer build .
working-directory: /home/runner/work/packer-do-custom-images/demo
The runs-on directive is missing (commented!), just add/uncomment it after the name, like:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
To fix the issue.
I would suggest to use the actionlint tool to discover error like this, as example:
> actionlint .github/workflows/test.yaml
.github/workflows/test.yaml:35:3: "runs-on" section is missing in job "build" [syntax-check]
|
35 | build:
| ^~~~~~
UPDATE:
As side notes also the env variable as issue: you should use : instead of = like:
- name: Packer init
env:
DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }}

Why github actions cant timeout a single job

I have a workflow in which a run request runs infinitely. i want to stop that run after 5 minutes of it running.
my workflow file:-
name: MSBuild
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
# Path to the solution file relative to the root of the project.
SOLUTION_FILE_PATH: ./genshincheat.sln
# Configuration type to build.
# You can convert this to a build matrix if you need coverage of multiple configuration types.
# https://docs.github.com/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
BUILD_CONFIGURATION: Release
permissions:
contents: read
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout#v1
with:
submodules: recursive
- name: Add MSBuild to PATH
uses: microsoft/setup-msbuild#v1.0.2
- name: Restore NuGet packages
working-directory: ${{env.GITHUB_WORKSPACE}}
run: nuget restore ${{env.SOLUTION_FILE_PATH}}
- name: Build
working-directory: ${{env.GITHUB_WORKSPACE}}
# Add additional options to the MSBuild command line here (like platform or verbosity level).
# See https://learn.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}}
- uses: montudor/action-zip#v1
with:
args: zip -qq -r bin.zip dir
- uses: actions/checkout#v2
- run: mkdir -p path/to/artifact
- run: echo hello > path/to/artifact/world.txt
- uses: actions/upload-artifact#v3
with:
name: bin.zip
path: ./bin.zip
the "build" runs infinitely any way to stop it after 5 mins so it can carry out next jobs? it runs infinitely becauseafter build it runs the built program so i cant exit that ;-;. any help is appreciated
There are different fields that can help you achieve what you want.
At the job level: job.<id>.timeout-minutes (defining a job timeout)
At the step level: job.<id>.steps.timeout-minutes (defining a step timeout)
Which would look like this in your case:
At the job level:
build:
runs-on: windows-latest
timeout-minutes: 5
steps:
[...]
At the step which never ends (example):
- name: Build
timeout-minutes: 5
working-directory: ${{env.GITHUB_WORKSPACE}}
# Add additional options to the MSBuild command line here (like platform or verbosity level).
# See https://learn.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}}
Another reference on the Github Community

Get Branch commit version in gitlab ci

I have a requirement to zip the artifacts folder and name it with last commit version name in gitlab-ci.yml file to the below exisiting code
build-docker:
stage: build
before_script:
- git clean -xfdf
tags:
- docker-linux
image: node
script:
- echo "Start building App"
- npm install
- npm run build
- npm run test
- echo "Build successfully!"
- if [ $CI_COMMIT_REF_NAME == "master" ]; then node ./sonarqube-scanner.js --serverUrl $SONAR_URL --token $SONAR_PAT --projectName 'blk-support-portal' --sources 'src'; fi;
artifacts:
paths:
- dist/
build-docker:
stage: build
before_script:
- git clean -xfdf
tags:
- docker-linux
image: node
script:
- echo "Start building App"
- npm install
- npm run build
- npm run test
- echo "Build successfully!"
- if [ $CI_COMMIT_REF_NAME == "master" ]; then node ./sonarqube-scanner.js --serverUrl $SONAR_URL --token $SONAR_PAT --projectName 'blk-support-portal' --sources 'src'; fi;
artifacts:
paths:
- dist/
Thanks,
Rohith

Compiling with multiple scala versions

I wanted to run travis build against two Scala versions (2.12, 2.13) i.e crossCompilation, so I created two jobs for it, as logs were huge and there is a log limit of 4 MB in travis. So I created two jobs for it.Here is my travis.yml file. I am not so good with travis-ci. So I am struggling to run two jobs with different scala versions. Here is my travis.yml file:
language: scala
jdk:
- openjdk11
if: tag IS blank
services:
- mysql
addons:
apt:
sources:
- mysql-5.7-xenial
packages:
- mysql-server
dist: bionic
sudo: required
before_install:
- echo -e "machine github.com\n login $GITHUB_AUTH_TOKEN" > ~/.netrc
- mysql -e 'CREATE DATABASE IF NOT EXISTS $ZZ_API_TEST_DB_NAME;'
- sudo mysql -e "use mysql; update user set authentication_string=PASSWORD('') where user='$ZZ_API_DB_USERNAME'; update user set plugin='mysql_native_password';FLUSH PRIVILEGES;"
- sudo mysql_upgrade -u $ZZ_API_DB_USERNAME
- sudo service mysql restart
git:
depth: false
env:
global:
- ZZ_API_DB_HOST="localhost:3306"
- ZZ_API_TEST_DB_NAME=issue_management_test
- ZZ_API_DB_USERNAME=root
- ZZ_API_DB_PASSWORD=""
- SCALA_2_12="2.12.8"
- SCALA_2_13="2.13.3"
before_cache:
- find $HOME/.ivy2 -name "ivydata-*.properties" -delete
- find $HOME/.sbt -name "*.lock" -delete
cache:
directories:
- $HOME/.sbt/boot/scala*
- $HOME/.sbt/cache
- $HOME/.sbt/launchers
- $HOME/.ivy2/cache
- $HOME/.coursier
stages
- version_2.12
- version_2.13
jobs:
include:
- stage: version_2.12
name: "2.12.8"
script:
- if [ "$TRAVIS_EVENT_TYPE" == "cron" ]; then sbt coverage $SCALA_2_12 test ; else sbt $SCALA_2_12 test; fi
after_success:
- sbt coverageReport coverageAggregate
deploy:
- provider: script
skip_cleanup: true
script: sbt publish
on:
all_branches: true
condition: $TRAVIS_BRANCH != master || $TRAVIS_BRANCH != develop
- provider: script
skip_cleanup: true
before_deploy:
- travis/before_deploy.sh
script: sbt publish
on:
branch: develop
- provider: script
skip_cleanup: true
script: travis/release.sh
on:
branch: master
- stage: version_2.13
name: "2.13.3"
script:
- if [ "$TRAVIS_EVENT_TYPE" == "cron" ]; then sbt coverage $SCALA_2_13 test ; else sbt $SCALA_2_13 test; fi
after_success:
- sbt coverageReport coverageAggregate
deploy:
- provider: script
skip_cleanup: true
script: sbt publish
on:
all_branches: true
condition: $TRAVIS_BRANCH != master || $TRAVIS_BRANCH != develop
- provider: script
skip_cleanup: true
before_deploy:
- travis/before_deploy.sh
script: sbt publish
on:
branch: develop
- provider: script
skip_cleanup: true
script: travis/release.sh
on:
branch: master
I am not much familiar with travis, somehow its not picking
- SCALA_2_12="2.12.8"
- SCALA_2_13="2.13.3"
and this command:
- if [ "$TRAVIS_EVENT_TYPE" == "cron" ]; then sbt coverage $SCALA_2_12 test ; else sbt $SCALA_2_12 test; fi
is failing in travis build.
How to specify two different scala versions for these two different task, someone please help on this
It worked finally, this change I did,
changed $SCALA_2_13 to ++$SCALA_2_13

Gitlab yaml to azure pipelines yaml file

I'm trying to convert but after reading some sources im not sure how I can convert this part of yaml code that works with gitlab CI to azure pipelines yaml:
build:
stage: build
script:
- npm run build
artifacts:
paths:
- dist
only:
- master
deploy:
stage: deploy
script:
- npm i -g netlify-cli
- netlify deploy --site $NETLIFY_SITE_ID --auth $NETLIFY_AUTH_TOKEN --prod
dependencies:
- build
only:
- master
Especially I want to set the artifact path in the build stage and then somehow set that in the deploy stage.
Here how it looks now in my azure-pipelines yaml:
- script: |
npm run build
displayName: 'Build'
- script: |
npm i -g netlify-cli
netlify deploy --site $NETLIFY_SITE_ID --auth $NETLIFY_AUTH_TOKEN --prod
displayName: 'Deploy'
See below sample:
variables:
- name: netlify.site.id
value: {value}
- name: netlify.auth.token
value: {token}
trigger:
- master
pool:
vmImage: 'vs2017-win2016'
stages:
- stage: Build
jobs:
- job: ARM
steps:
- script: npm -version
- publish: $(System.DefaultWorkingDirectory)
artifact: dist
- stage: Deploy
dependsOn: Build
condition: succeeded()
jobs:
- job: APP
steps:
- bash: |
npm i -g netlify-cli
netlify deploy --site $(netlify.site.id) --auth $(netlify.auth.token) --prod
Tip1: If the value of netlify.auth.token and netlify.site.id is very private for you, and you do not want it public in YAML. You can store them in variable group. And then change the Variables part as:
variables:
- group: {group name}
See this doc.
Tip2: For the stage dependency, you can use dependsOn keyword in VSTS yaml to achieve the dependency. See this.
Tip3: In VSTS, you must specify stages, jobs and steps which used as the entry point for the server to compile the respective part.
A stage is a collection of related jobs.
A job is a collection of steps to be run by an agent or on the
server.
Steps are a linear sequence of operations that make up a job.
Tip4: To achieve publishing artifacts in VSTS with YAML, there has 2 different format. One is what I show for you above. The publish keyword is a shortcut for the Publish Pipeline Artifact task.
Another one format, see this Publishing artifacts