Skip to content

Commit

Permalink
147 and 160 (#43)
Browse files Browse the repository at this point in the history
* Add travis configuration for development & stage branches

* Remove latest env-file & production and stage cypress configurations

* MM-155 Change Travis configuration to build and push images from environment branches (#38)

* namespace info

* better positioning of tooltip

* icons moved

* Add travis configuration for development & stage branches

* Remove latest env-file & production and stage cypress configurations

Co-authored-by: Anton <anton.jyrkiainen@helsinki.fi>

* dev.yml and some small changes

* testing trigger

* changed login params

* testing env changes

* specified cypress json

* more env updates

* testing env

* debug logs

* testing old env

* Removed console logs

* removed push trigger

* env updates

* cypress envs only needed locally and in dev

* removed redundant e2e stuff

* credentials added to requests

* removed redundant cypress things from travis-build.sh

* 147 and 160 Session improvements and github actions  (#42)

* namespace info

* better positioning of tooltip

* icons moved

* Add travis configuration for development & stage branches

* Remove latest env-file & production and stage cypress configurations

* MM-155 Change Travis configuration to build and push images from environment branches (#39)

* Add travis configuration for development & stage branches

* Remove latest env-file & production and stage cypress configurations

* dev.yml and some small changes

* testing trigger

* changed login params

* testing env changes

* specified cypress json

* more env updates

* testing env

* debug logs

* testing old env

* Removed console logs

* removed push trigger

* env updates

* cypress envs only needed locally and in dev

* removed redundant e2e stuff

* credentials added to requests

* removed redundant cypress things from travis-build.sh

Co-authored-by: Petteri Pesonen <teemu.p.pesonen@gmail.com>

Co-authored-by: Petteri Pesonen <teemu.p.pesonen@gmail.com>
  • Loading branch information
ahjyrkia and Pesonet1 authored Nov 3, 2020
1 parent fe14cb3 commit 3a350d2
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 133 deletions.
13 changes: 7 additions & 6 deletions .env
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Shared environment variables. Add env variables specific to your environment in .env.development.local
# Shared environment variables. Add env variables specific to your environment in .env

REACT_APP_API_URL=http://localhost:4000
REACT_APP_JORE_API_URL=https://dev.kartat.hsl.fi/jore/graphql
REACT_APP_CLIENT_ID=7833861618225795
REACT_APP_CLIENT_SECRET=
REACT_APP_REDIRECT_URI=http://localhost:3000
HSL_TESTING_HSLID_USERNAME=
HSL_TESTING_HSLID_PASSWORD=
DOMAINS_ALLOWED_TO_GENERATE=
REACT_APP_NAMESPACE=hsl-kartta
REACT_APP_NAMESPACE=hsl-kartta

CYPRESS_TESTING_HSLID_USERNAME=
CYPRESS_TESTING_HSLID_PASSWORD=
CYPRESS_HSLID_CLIENT_ID=
CYPRESS_HSLID_CLIENT_SECRET=
13 changes: 7 additions & 6 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Shared environment variables. Add env variables specific to your environment in .env.development.local
# Shared environment variables. Add env variables specific to your environment in .env

REACT_APP_API_URL=https://dev.kartat.hsl.fi/julkaisin-api
REACT_APP_JORE_API_URL=https://dev.kartat.hsl.fi/jore/graphql
REACT_APP_CLIENT_ID=7833861618225795
CLIENT_SECRET=
REACT_APP_REDIRECT_URI=https://dev.kartat.hsl.fi/julkaisin
HSL_TESTING_HSLID_USERNAME=
HSL_TESTING_HSLID_PASSWORD=
DOMAINS_ALLOWED_TO_GENERATE=
REACT_APP_NAMESPACE=hsl-kartta
REACT_APP_NAMESPACE=hsl-kartta

CYPRESS_TESTING_HSLID_USERNAME=
CYPRESS_TESTING_HSLID_PASSWORD=
CYPRESS_HSLID_CLIENT_ID=
CYPRESS_HSLID_CLIENT_SECRET=
8 changes: 2 additions & 6 deletions .env.production
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# Shared environment variables. Add env variables specific to your environment in .env.development.local
# Shared environment variables. Add env variables specific to your environment in .env

REACT_APP_API_URL=https://prod.kartat.hsl.fi/julkaisin-api
REACT_APP_JORE_API_URL=https://prod.kartat.hsl.fi/jore/graphql
REACT_APP_CLIENT_ID=7833861618225795
CLIENT_SECRET=
REACT_APP_REDIRECT_URI=https://kartat.hsl.fi/julkaisin
HSL_TESTING_HSLID_USERNAME=
HSL_TESTING_HSLID_PASSWORD=
DOMAINS_ALLOWED_TO_GENERATE=
REACT_APP_NAMESPACE=hsl-kartta
REACT_APP_NAMESPACE=hsl-kartta
7 changes: 2 additions & 5 deletions .env.stage
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# Shared environment variables. Add env variables specific to your environment in .env.development.local
# Shared environment variables. Add env variables specific to your environment in .env

REACT_APP_API_URL=https://stage.kartat.hsl.fi/julkaisin-api
REACT_APP_JORE_API_URL=https://stage.kartat.hsl.fi/jore/graphql
REACT_APP_CLIENT_ID=7833861618225795
CLIENT_SECRET=
REACT_APP_REDIRECT_URI=https://stage.kartat.hsl.fi/julkaisin
HSL_TESTING_HSLID_USERNAME=
HSL_TESTING_HSLID_PASSWORD=
DOMAINS_ALLOWED_TO_GENERATE=
REACT_APP_NAMESPACE=hsl-kartta
35 changes: 35 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Test

on:
pull_request:
branches:
- development

jobs:
test-dev:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Cypress run
uses: cypress-io/github-action@v1
with:
config-file: /cypress.dev.json
env:
CYPRESS_BASE_URL: https://dev.kartat.hsl.fi/julkaisin
CYPRESS_HSLID_CLIENT_ID: ${{ secrets.CYPRESS_HSLID_CLIENT_ID }}
CYPRESS_HSLID_CLIENT_SECRET: ${{ secrets.CYPRESS_HSLID_CLIENT_SECRET }}
CYPRESS_TESTING_HSLID_USERNAME: ${{ secrets.CYPRESS_TESTING_HSLID_USERNAME }}
CYPRESS_TESTING_HSLID_PASSWORD: ${{ secrets.CYPRESS_TESTING_HSLID_PASSWORD }}
- name: Upload screenshot artifacts
uses: actions/upload-artifact@v1
if: failure()
with:
name: cypress-screenshots
path: cypress/screenshots
- name: Upload video artifacts
uses: actions/upload-artifact@v1
if: always()
with:
name: cypress-videos
path: cypress/videos
35 changes: 0 additions & 35 deletions constants.js

This file was deleted.

61 changes: 58 additions & 3 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
const fs = require('fs-extra');
const path = require('path');
const _ = require('lodash');
const dotenv = require('dotenv');

// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
Expand All @@ -11,7 +16,57 @@
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
async function getConfigurationByFile(file) {
if (!file) {
return {};
}

const pathToConfigFile = path.resolve(`cypress.${file}.json`);
return fs.readJson(pathToConfigFile);
}

async function readEnvVars() {
const config = {};

const appRoot = await fs.realpath(process.cwd());
const envPaths = [path.resolve(appRoot, '.env')];
const envObjects = [];

for (const envPath of envPaths) {
const pathExists = await fs.exists(envPath);

if (!pathExists) {
continue;
}

const envFile = await fs.readFile(envPath, 'utf8');
const envContent = dotenv.parse(envFile);
envObjects.push(envContent);
}

const combinedFiles = _.merge({}, ...envObjects);

const CYPRESS_PREFIX = /^CYPRESS_/i;

// Add CYPRESS-prefixed vars to the config.
Object.entries(combinedFiles).forEach(([key, value]) => {
config[key] = value;
});

// Add CYPRESS-prefixed vars from the environment to the config.
for (const [envName, envValue] of Object.entries(process.env)) {
if (envName.match(CYPRESS_PREFIX)) {
config[envName] = envValue;
}
}
return config;
}

module.exports = async (on, config) => {
const configFile = config.env.configFile || '';

const envVars = await readEnvVars();
const envConfig = await getConfigurationByFile(configFile);

return _.merge({}, config, { env: envVars }, envConfig);
};
16 changes: 8 additions & 8 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ Cypress.Commands.add('hslLogin', () => {
const AUTH_URI = 'https://hslid-uat.cinfra.fi/openid/token';
const AUTH_SCOPE = 'email https://oneportal.trivore.com/scope/groups.readonly';

const HSL_TESTING_HSLID_USERNAME = process.env.HSL_TESTING_HSLID_USERNAME || '';
const HSL_TESTING_HSLID_PASSWORD = process.env.HSL_TESTING_HSLID_PASSWORD || '';

const CLIENT_ID = process.env.REACT_APP_CLIENT_ID || '';
const { CLIENT_SECRET } = require('../../constants');
const CLIENT_ID = Cypress.env('CYPRESS_HSLID_CLIENT_ID');
const CLIENT_SECRET = Cypress.env('CYPRESS_HSLID_CLIENT_SECRET');
const HSLID_USERNAME = Cypress.env('CYPRESS_TESTING_HSLID_USERNAME');
const HSLID_PASSWORD = Cypress.env('CYPRESS_TESTING_HSLID_PASSWORD');

const authHeader = `Basic ${btoa(`${CLIENT_ID}:${CLIENT_SECRET}`)}`;

Expand All @@ -21,8 +20,8 @@ Cypress.Commands.add('hslLogin', () => {
body: {
scope: AUTH_SCOPE,
grant_type: 'password',
username: HSL_TESTING_HSLID_USERNAME,
password: HSL_TESTING_HSLID_PASSWORD,
username: HSLID_USERNAME,
password: HSLID_PASSWORD,
},
};

Expand All @@ -32,6 +31,7 @@ Cypress.Commands.add('hslLogin', () => {
expect(response.status).to.eq(200);
expect(access_token).to.be.ok;
// testing = QueryParams.testing
cy.visit(`/afterLogin?code=${access_token}&testing=true`);
cy.visit(`/?code=${access_token}&testing=true`);
cy.wait(3000);
});
});
6 changes: 0 additions & 6 deletions docker-deploy-tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ read -p "Tag: " TAG

DOCKER_TAG=${TAG:-production}
DOCKER_IMAGE=$ORG/hsl-map-publisher-ui:${DOCKER_TAG}
DOCKER_IMAGE_CYPRESS=$ORG/publisher-ui-e2e:dev

docker build --build-arg BUILD_ENV=${TAG:-production} -t $DOCKER_IMAGE .
docker push $DOCKER_IMAGE

if [[ $DOCKER_TAG == "dev" ]]; then
docker build --build-arg BUILD_ENV=dev -t $DOCKER_IMAGE_CYPRESS -f e2e.dockerfile .
docker push $DOCKER_IMAGE_CYPRESS
fi
22 changes: 0 additions & 22 deletions e2e.dockerfile

This file was deleted.

18 changes: 0 additions & 18 deletions e2e.package.json

This file was deleted.

7 changes: 1 addition & 6 deletions src/components/Generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import StopList from './StopList';
import BuildSelect from './BuildSelect';
import SelectTemplate from './SelectTemplate';

const allowedDomains = process.env.DOMAINS_ALLOWED_TO_GENERATE || 'hsl.fi';

const Root = styled.div`
display: flex;
flex-flow: column;
Expand Down Expand Up @@ -51,9 +49,6 @@ const Heading = styled.h2`

const Generator = props => {
const { commonStore, generatorStore } = props;
const user = commonStore.getUser();
const userDomain = user.split('@')[1];
const allowedToGenerate = allowedDomains.split(',').includes(userDomain);
const stopCount = generatorStore.rows
.filter(({ rowId }) => generatorStore.checkedRows.includes(rowId))
.map(({ stopIds }) => stopIds.length)
Expand Down Expand Up @@ -201,7 +196,7 @@ const Generator = props => {
/>
<RaisedButton
data-cy="generate-button"
disabled={(stopCount < 1 || !generatorStore.buildId) && !allowedToGenerate}
disabled={stopCount < 1 || !generatorStore.buildId}
onClick={() => {
if (commonStore.templateIsDirty) {
commonStore.showConfirm(
Expand Down
1 change: 1 addition & 0 deletions src/util/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ async function createRequest(path, method = 'GET', body) {
? {}
: {
method,
credentials: 'include',
body: JSON.stringify(body),
};

Expand Down
12 changes: 0 additions & 12 deletions travis-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,6 @@ BUILD_AND_PUSH_BRANCHES=('development', 'stage', 'master')
if [[ $TRAVIS_BRANCH == "development" ]]; then
DOCKER_TAG=dev
BUILD_ENV=dev

echo "Building cypress test image with env -> dev and tag -> dev"

DOCKER_IMAGE_CYPRESS=$ORG/publisher-ui-e2e:dev
docker build --build-arg BUILD_ENV=dev -t $DOCKER_IMAGE_CYPRESS -f e2e.dockerfile .

if [[ $TRAVIS_PULL_REQUEST == "false" ]]; then
echo "Pushing builded cypress test image to registry with tag -> dev"

docker login -u $DOCKER_USER -p $DOCKER_AUTH
docker push $DOCKER_IMAGE_CYPRESS
fi
fi

if [[ $TRAVIS_BRANCH == "stage" ]]; then
Expand Down

0 comments on commit 3a350d2

Please sign in to comment.