Skip to content

Commit

Permalink
build: switch from travis-ci to github actions (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyubisation authored Nov 7, 2019
1 parent 302dc24 commit 8a83ff5
Show file tree
Hide file tree
Showing 16 changed files with 1,661 additions and 1,650 deletions.
336 changes: 336 additions & 0 deletions .github/workflows/continuous-integration-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,336 @@
name: Continuous Integration
on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
env:
NODE_OPTIONS: --max_old_space_size=6144
steps:
- name: Shallow checkout
uses: actions/checkout@v1
with:
fetch-depth: 1
- uses: actions/setup-node@v1
with:
node-version: 12

- name: Restore dependencies from cache
uses: actions/cache@v1
id: node_modules_cache
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies
if: steps.node_modules_cache.outputs.cache-hit != 'true'
run: npm ci

- name: Migrate public to business components
run: npm run build:angular-business:public2business

- name: Restore @sbb-esta/angular-core from cache
uses: actions/cache@v1
id: sbb_esta_angular_core_cache
with:
path: dist/sbb-esta/angular-core
key: "ng-sbb-esta-angular-core-\
${{ hashFiles('**/projects/sbb-esta/angular-core/**/*.ts') }}-\
${{ hashFiles('**/projects/sbb-esta/angular-core/**/*.scss') }}"
- name: Build @sbb-esta/angular-core
if: steps.sbb_esta_angular_core_cache.outputs.cache-hit != 'true'
run: npm run build:angular-core

- name: Restore @sbb-esta/angular-icons from cache
uses: actions/cache@v1
id: sbb_esta_angular_icons_cache
with:
path: dist/sbb-esta/angular-icons
key: "ng-sbb-esta-angular-icons-\
${{ hashFiles('**/projects/sbb-esta/angular-icons/**/*.ts') }}"
- name: Build @sbb-esta/angular-icons
if: steps.sbb_esta_angular_icons_cache.outputs.cache-hit != 'true'
run: npm run build:angular-icons

- name: Restore @sbb-esta/angular-keycloak from cache
uses: actions/cache@v1
id: sbb_esta_angular_keycloak_cache
with:
path: dist/sbb-esta/angular-keycloak
key: "ng-sbb-esta-angular-keycloak-\
${{ hashFiles('**/projects/sbb-esta/angular-keycloak/**/*.ts') }}"
- name: Build @sbb-esta/angular-keycloak
if: steps.sbb_esta_angular_keycloak_cache.outputs.cache-hit != 'true'
run: npm run build:angular-keycloak

- name: Restore @sbb-esta/angular-public from cache
uses: actions/cache@v1
id: sbb_esta_angular_public_cache
with:
path: dist/sbb-esta/angular-public
key: "ng-sbb-esta-angular-public-\
${{ hashFiles('**/projects/sbb-esta/angular-public/**/*.ts') }}-\
${{ hashFiles('**/projects/sbb-esta/angular-public/**/*.html') }}-\
${{ hashFiles('**/projects/sbb-esta/angular-public/**/*.scss') }}"
- name: Build @sbb-esta/angular-public
if: steps.sbb_esta_angular_public_cache.outputs.cache-hit != 'true'
run: npm run build:angular-public

- name: Restore @sbb-esta/angular-business from cache
uses: actions/cache@v1
id: sbb_esta_angular_business_cache
with:
path: dist/sbb-esta/angular-business
key: "ng-sbb-esta-angular-business-\
${{ hashFiles('**/projects/sbb-esta/angular-business/**/*.ts') }}-\
${{ hashFiles('**/projects/sbb-esta/angular-business/**/*.html') }}-\
${{ hashFiles('**/projects/sbb-esta/angular-business/**/*.scss') }}"
- name: Build @sbb-esta/angular-business
if: steps.sbb_esta_angular_business_cache.outputs.cache-hit != 'true'
run: npm run build:angular-business

- name: Store build artifacts
uses: actions/upload-artifact@v1
with:
name: dist-sbb-esta
path: dist/sbb-esta

lint:
runs-on: ubuntu-latest
needs: build
steps:
- name: Shallow checkout
uses: actions/checkout@v1
with:
fetch-depth: 1
- uses: actions/setup-node@v1
with:
node-version: 12

- name: Restore dependencies from cache
uses: actions/cache@v1
id: node_modules_cache
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies
if: steps.node_modules_cache.outputs.cache-hit != 'true'
run: npm ci

- name: Create lint output directory
run: mkdir lint
- name: Linting @sbb-esta/angular-core
run: npx ng lint @sbb-esta/angular-core --format=json > lint/core.json
- name: Linting @sbb-esta/angular-icons
run: npx ng lint @sbb-esta/angular-icons --format=json > lint/icons.json
- name: Linting @sbb-esta/angular-keycloak
run: npx ng lint @sbb-esta/angular-keycloak --format=json > lint/keycloak.json
- name: Linting @sbb-esta/angular-public
run: npx ng lint @sbb-esta/angular-public --format=json > lint/public.json
- name: Linting @sbb-esta/angular-business
run: npx ng lint @sbb-esta/angular-business --format=json > lint/business.json
- name: Linting @sbb-esta/angular-showcase
run: npx ng lint angular-showcase --format=json > lint/showcase.json

- name: Save lint results
uses: actions/upload-artifact@v1
with:
name: lint-report
path: lint

test:
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push'
env:
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
steps:
- name: Shallow checkout
uses: actions/checkout@v1
with:
fetch-depth: 1
- uses: actions/setup-node@v1
with:
node-version: 12

- name: Restore dependencies from cache
uses: actions/cache@v1
id: node_modules_cache
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies
if: steps.node_modules_cache.outputs.cache-hit != 'true'
run: npm ci

- name: Restore build artifacts
uses: actions/download-artifact@v1
with:
name: dist-sbb-esta
path: dist/sbb-esta

- name: Testing @sbb-esta/angular-core
run: npx ng test @sbb-esta/angular-core -c ci
- name: Testing @sbb-esta/angular-keycloak
run: npx ng test @sbb-esta/angular-keycloak -c ci
- name: Testing @sbb-esta/angular-public
run: npx ng test @sbb-esta/angular-public -c ci
- name: Testing @sbb-esta/angular-business
run: npx ng test @sbb-esta/angular-business -c ci

- name: Save test results
uses: actions/upload-artifact@v1
with:
name: coverage-report
path: coverage

test-pr:
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'pull_request'
steps:
- name: Shallow checkout
uses: actions/checkout@v1
with:
fetch-depth: 1
- uses: actions/setup-node@v1
with:
node-version: 12

- name: Restore dependencies from cache
uses: actions/cache@v1
id: node_modules_cache
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies
if: steps.node_modules_cache.outputs.cache-hit != 'true'
run: npm ci

- name: Restore build artifacts
uses: actions/download-artifact@v1
with:
name: dist-sbb-esta
path: dist/sbb-esta

- name: Testing @sbb-esta/angular-core PR
run: npx ng test @sbb-esta/angular-core -c pr
- name: Testing @sbb-esta/angular-keycloak PR
run: npx ng test @sbb-esta/angular-keycloak -c pr
- name: Testing @sbb-esta/angular-public PR
run: npx ng test @sbb-esta/angular-public -c pr
- name: Testing @sbb-esta/angular-business PR
run: npx ng test @sbb-esta/angular-business -c pr

- name: Save test results
uses: actions/upload-artifact@v1
with:
name: coverage-report
path: coverage

sonar:
runs-on: ubuntu-latest
needs: [lint, test]
if: github.event_name == 'push'
steps:
- name: Full checkout
uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12

- name: Restore dependencies from cache
uses: actions/cache@v1
id: node_modules_cache
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies
if: steps.node_modules_cache.outputs.cache-hit != 'true'
run: npm ci

- name: Prepare sonar configuration
run: node scripts/sonar.js
- name: Restore lint artifacts
uses: actions/download-artifact@v1
with:
name: lint-report
path: lint
- name: Restore test artifacts
uses: actions/download-artifact@v1
with:
name: coverage-report
path: coverage
- name: Adapt lcov paths
run: find ./coverage -name lcov.info -type f -exec sed -i -e "s|SF:$GITHUB_WORKSPACE|SF:/github/workspace|g" {} \;
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@v1.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

showcase:
runs-on: ubuntu-latest
needs: build
steps:
- name: Shallow checkout
uses: actions/checkout@v1
with:
fetch-depth: 1
- uses: actions/setup-node@v1
with:
node-version: 12

- name: Restore dependencies from cache
uses: actions/cache@v1
id: node_modules_cache
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies
if: steps.node_modules_cache.outputs.cache-hit != 'true'
run: npm ci

- name: Restore build artifacts
uses: actions/download-artifact@v1
with:
name: dist-sbb-esta
path: dist/sbb-esta

- name: Build showcase
run: npm run build:angular-showcase
- name: Copy showcase package.json
run: cp projects/angular-showcase/package.json dist/angular-showcase

- name: Save showcase artifact
uses: actions/upload-artifact@v1
with:
name: showcase
path: dist/angular-showcase

deploy-staging:
runs-on: ubuntu-latest
needs: showcase
if: github.event_name == 'pull_request'
env:
PR_NUMBER: ${{ github.event.number }}
steps:
- uses: actions/setup-node@v1
with:
node-version: 12
- name: Restore showcase artifact
uses: actions/download-artifact@v1
with:
name: showcase
path: dist/angular-showcase
- name: Assign showcase version
run: sed -i "s/0.0.0-PLACEHOLDER/0.0.0-$PR_NUMBER/g" dist/angular-showcase/package.json
- name: Pack showcase
run: |
cd dist/angular-showcase
npm pack
- name: Deploy to staging
run: |
curl --url https://angular-staging.app.sbb.ch/$PR_NUMBER \
-X POST --user sbb:ezUxDHgb6rAHTDU0HLHJ \
-F "tarball=@dist/angular-showcase/sbb-esta-angular-showcase-0.0.0-$PR_NUMBER.tgz"
Loading

0 comments on commit 8a83ff5

Please sign in to comment.