Dimitri Kopriwa
Dimitri Kopriwa

Reputation: 14445

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

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:

Project:

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?

Upvotes: 2

Views: 417

Answers (1)

keradus
keradus

Reputation: 534

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/

Upvotes: 3

Related Questions