Skip to content

Commit

Permalink
Rac 191 (#12583)
Browse files Browse the repository at this point in the history
* RA-193: Fix lib build

* RAC-193: Add Extract workflow and bump-version script

* RAC-193: Add extract github action

* RAC-193: Add styled components types

* RAC-191: Add github action to test

* RAC-191: Retry github test action

* RAC-191: Retry github test action

* RAC-191: Add types

* RAC-191: Add types

* RAC-191: Test

* RAC-191: Fix unit test for now

* RAC-191: Fix unit test for now

* RAC-191: Now headless

* RAC-191: Upload artifact if failure

* RAC-191: Upload artifact if failure

* RAC-191: Fix font-weight

* RAC-191: Disable visual tests for now

* RAC-191:

* Bump to version

* RAC-191: Fix noRef onClick documentation

* Bump to version

* RAC-191: revert commit

* Bump to version

* RAC-191: add automatic tag

* Bump to version 0.0.5

* RAC-191: fix pim-comunity-dev push on master

* Bump to version 0.0.6

* RAC-191: dsm branch is the new black

* RAC-191: do not remove lib from .gitignore, lib is ignored only on akeneo-pim-community

Co-authored-by: Samir <samir.boulil@akeneo.com>
Co-authored-by: Github Actions <contact@akeneo.com>
Co-authored-by: Steven VAIDIE <steven.vaidie@gmail.com>
  • Loading branch information
4 people committed Aug 14, 2020
1 parent 125ed2e commit 894394d
Show file tree
Hide file tree
Showing 18 changed files with 378 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .github/actions/extract/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM alpine:3.10

RUN apk add --no-cache git

COPY entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
21 changes: 21 additions & 0 deletions .github/actions/extract/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Carles Pina Estany

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
61 changes: 61 additions & 0 deletions .github/actions/extract/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# github-action-push-to-another-repository

Used to push generated files from a directory from Git Action step into another repository on Github.

E.g.
Repository pandoc-test contains Markdown and a Git Action to generate, using Pandoc, an output: HTML, PDF, odt, epub, etc.

Repository pandoc-test-output: contains only the generated files from the first Git Action. Pushed here with github-action-push-to-another-repository

And pandoc-test-output can have Git Pages to give access to the files (or just links to the raw version of the files)

## Inputs
### `source-directory` (argument)
From the repository that this Git Action is executed the directory that contains the files to be pushed into the repository.

### `destination-github-username` (argument)
For the repository `https://github.com/cpina/push-to-another-repository-output` is `cpina`. It's also used for the `Author:` in the generated git messages.

### `destination-repository-name` (argument)
For the repository `https://github.com/cpina/push-to-another-repository-output` is `push-to-another-repository-output`

### `user-email` (argument)
The email that will be used for the commit in the destination-repository-name.

### `API_TOKEN_GITHUB` (environment)
E.g.:
`API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}`

Generate your personal token following the steps:
* Go to the Github Settings (on the right hand side on the profile picture)
* On the left hand side pane click on "Developer Settings"
* Click on "Personal Access Tokens" (also available at https://github.com/settings/tokens)
* Generate a new token, choose "Repo". Copy the token.

Then make the token available to the Github Action following the steps:
* Go to the Github page for the repository that you push from, click on "Settings"
* On the left hand side pane click on "Secrets"
* Click on "Add a new secret" and name it "API_TOKEN_GITHUB"

## Example usage
```yaml
- name: Pushes to another repository
uses: cpina/github-action-push-to-another-repository@master
env:
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
with:
source-directory: 'output'
destination-github-username: 'cpina'
destination-repository-name: 'pandoc-test-output'
user-email: carles3@pina.cat
```

Working example:

https://github.com/cpina/push-to-another-repository-example/blob/master/.github/workflows/ci.yml

It generates files from:
https://github.com/cpina/push-to-another-repository-example

To:
https://github.com/cpina/push-to-another-repository-output
30 changes: 30 additions & 0 deletions .github/actions/extract/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: 'Push directory to another repository'
description: 'Useful to push files to another repository to be used, for example, via github pages'
inputs:
source-directory:
description: 'Source directory from the origin directory'
required: true
destination-github-username:
description: 'Name of the destination username/organization'
required: true
destination-repository-name:
description: 'Destination repository'
required: true
destination-branch:
description: 'The branch to push to'
required: true
user-email:
description: 'Email for the git commit'
required: true
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.source-directory }}
- ${{ inputs.destination-github-username }}
- ${{ inputs.destination-repository-name }}
- ${{ inputs.user-email }}
- ${{ inputs.destination-branch }}
branding:
icon: 'git-commit'
color: 'green'
30 changes: 30 additions & 0 deletions .github/actions/extract/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh -l

echo "Starts"
FOLDER="$1"
GITHUB_USERNAME="$2"
GITHUB_REPO="$3"
USER_EMAIL="$4"
BRANCH="$5"

CLONE_DIR=$(mktemp -d)

# Setup git
git config --global user.email "$USER_EMAIL"
git config --global user.name "$GITHUB_USERNAME"
git clone "https://$API_TOKEN_GITHUB@github.com/$GITHUB_USERNAME/$GITHUB_REPO.git" "$CLONE_DIR" --branch "$BRANCH"

# Copy files into the git and deletes all git
find "$CLONE_DIR" | grep -v "^$CLONE_DIR/\.git" | grep -v "^$CLONE_DIR$" | xargs rm -rf # delete all files (to handle deletions)

rm -rf "$CLONE_DIR"/.github
rm "$CLONE_DIR"/.gitignore

cp -r "$FOLDER"/. "$CLONE_DIR"

cd "$CLONE_DIR"
git status

git add .
git commit --message "Update from https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA"
git push origin "$BRANCH"
60 changes: 60 additions & 0 deletions .github/workflows/dsm-extract.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Extract DSM
on:
push:
branches:
- dsm
paths:
- 'akeneo-design-system/**'
jobs:
build:
name: Create a lib build
runs-on: ubuntu-latest
steps:
- name: Checkout current branch
uses: actions/checkout@v2
- name: Use Node.js 13
uses: actions/setup-node@v1
with:
node-version: 13.13
- name: Install Packages
run: cd akeneo-design-system && yarn install
- name: Bump package version
run: cd akeneo-design-system && node .github/workflows/bump-version.js $GITHUB_EVENT_PATH && echo "::set-output name=new_version::$(node .github/workflows/get-version.js)"
id: generate_new_dsm_version
- name: Push updated version
# Check we are able to push on a protected branch (like master)
run: |
git config --global user.email "contact@akeneo.com" && \
git config --global user.name "Github Actions" && \
git add akeneo-design-system/package.json && \
git commit -m "Bump to version ${{steps.generate_new_dsm_version.outputs.new_version}}" && \
git push
- name: Build library
run: cd akeneo-design-system && yarn run lib:build:prod
- uses: actions/upload-artifact@v1
with:
name: Lib
path: akeneo-design-system/lib

extract:
name: Extract to DSM dedicated repo
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout the current branch
uses: actions/checkout@v2.3.2
- name: Download the lib artifact
uses: actions/download-artifact@v1
with:
name: Lib
path: akeneo-design-system/lib
- name: Pushes to dsm repository
uses: ./.github/actions/extract
env:
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
with:
source-directory: akeneo-design-system
destination-github-username: 'samirboulil'
destination-repository-name: 'dsm'
user-email: contact@akeneo.com
destination-branch: 'master'
28 changes: 28 additions & 0 deletions .github/workflows/dsm-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test DSM
on:
pull_request:
paths:
- 'akeneo-design-system/**'
# Maybe we can launch unit & visual in parallel in separate jobs
jobs:
test:
name: Launch tests on the DSM
runs-on: ubuntu-latest
steps:
- name: checkout:master
uses: actions/checkout@v2
- name: Use Node.js 13
uses: actions/setup-node@v1
with:
node-version: 13.13
- name: Install Packages
run: cd akeneo-design-system && yarn install
- name: Launch lint checks
run: cd akeneo-design-system && yarn lint:check
- name: Launch tests
run: cd akeneo-design-system && yarn test:run
- uses: actions/upload-artifact@v2
if: failure()
with:
name: test-folder
path: akeneo-design-system/src
55 changes: 55 additions & 0 deletions akeneo-design-system/.github/workflows/bump-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

'use strict';

const {execSync} = require('child_process');
const fs = require('fs');

const filePath = process.argv[2];

if (typeof filePath === 'undefined') {
console.log(`usage: ${process.argv[0]} ${process.argv[1]} path_to_webhook_event.json`);

return;
}

// Let's define an enum for our bump levels
const BumpLevelEnum = {
Patch: 0,
Minor: 1,
Major: 2,
}
Object.freeze(BumpLevelEnum);

// Extract the bump level to extract from the commit message
const getCommitMessageBumpLevel = (message) => {
if (message.includes('#major')) return BumpLevelEnum.Major;
if (message.includes('#minor')) return BumpLevelEnum.Minor;

return BumpLevelEnum.Patch;
}

const getBumpNameFromBumpLevel = (bumpLevel) => {
switch (bumpLevel) {
case BumpLevelEnum.Patch:
return 'patch';
case BumpLevelEnum.Minor:
return 'minor';
case BumpLevelEnum.Major:
return 'major';
default:
throw Error('Invalid bump level');
}
}

const rawdata = fs.readFileSync(filePath);
const githubEvent = JSON.parse(rawdata);

const levelToBump = githubEvent.commits.reduce((currentBumpLevel, commit) => {
const bumpLevel = getCommitMessageBumpLevel(commit.message);

return bumpLevel > currentBumpLevel ? bumpLevel : currentBumpLevel;
}, BumpLevelEnum.Patch);

execSync(`npm --no-git-tag-version version ${getBumpNameFromBumpLevel(levelToBump)}`);

console.log(JSON.parse(fs.readFileSync('./package.json')).version);
24 changes: 24 additions & 0 deletions akeneo-design-system/.github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Deploy
on:
push:
branches:
- master
jobs:
master:
runs-on: ubuntu-latest
steps:
- name: checkout:master
uses: actions/checkout@v2
- name: Use Node.js 13
uses: actions/setup-node@v1
with:
node-version: 13.13
- name: Install Packages
run: yarn install
- name: Build storybook
run: yarn run storybook:build
- name: Deploy to gh-pages
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
publish_dir: ./storybook-static
5 changes: 5 additions & 0 deletions akeneo-design-system/.github/workflows/get-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

const fs = require('fs');

console.log(JSON.parse(fs.readFileSync('./package.json')).version);
20 changes: 20 additions & 0 deletions akeneo-design-system/.github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Tag
on:
push:
branches:
- master
paths:
- package.json
jobs:
master:
runs-on: ubuntu-latest
steps:
- name: Checkout current branch
uses: actions/checkout@v2
- name: Create tag
run: |
git config --global user.email "contact@akeneo.com" && \
git config --global user.name "Github Actions" && \
git tag -a v$(node .github/workflows/get-version.js) -m "Version $(node .github/workflows/get-version.js)"
- name: Push tag
run: git push origin v$(node .github/workflows/get-version.js)
2 changes: 1 addition & 1 deletion akeneo-design-system/jest-puppeteer.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
launch: {
dumpio: true,
headless: false,
headless: true,
},
server: {
command: 'yarn storybook:ci',
Expand Down
9 changes: 6 additions & 3 deletions akeneo-design-system/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"name": "akeneo-design-system",
"version": "0.0.1",
"version": "0.0.6",
"description": "Akeneo design system",
"main": "lib/index.js",
"scripts": {
"prebuild": "rimraf lib && yarn test:run && yarn lint:check && yarn ts-build",
"prebuild-dev": "rimraf lib && yarn ts-build",
"prebuild-watch": "find lib -name \"*.d.ts\" -delete && yarn ts-build",
"ts-build": "tsc -p ./tsconfig.build.json --emitDeclarationOnly",
"check-types": "tsc",
"check-types:watch": "yarn check-types -- --watch",
"test:run": "yarn test:unit:run && yarn test:visual:run",
"test:run": "yarn test:unit:run",
"test:unit:run": "jest --config ./jest.unit.config.js",
"test:visual:run": "jest --config ./jest.visual.config.js",
"test:unit:watch": "jest --watch",
Expand All @@ -19,7 +20,7 @@
"storybook:ci": "start-storybook -p 6006 --ci",
"storybook:build": "build-storybook",
"lib:build:prod": "yarn prebuild && export NODE_ENV=production && rollup -c",
"lib:build:watch": "yarn prebuild-dev && export NODE_ENV=dev && rollup --watch -c",
"lib:build:watch": "yarn prebuild-watch && export NODE_ENV=dev && rollup --watch -c",
"lib:build:analyze": "yarn build:prod --config-analyze"
},
"author": "akeneo",
Expand All @@ -46,6 +47,8 @@
"@types/jest-environment-puppeteer": "^4.3.2",
"@types/jest-image-snapshot": "^3.1.0",
"@types/puppeteer": "^3.0.1",
"@types/styled-components": "^5.1.2",
"@types/testing-library__jest-dom": "^5.9.2",
"babel-loader": "8.0.5",
"jest": "^26.3.0",
"jest-image-snapshot": "^4.1.0",
Expand Down

0 comments on commit 894394d

Please sign in to comment.