Skip to content

Commit

Permalink
feat: add base prepare release pr script
Browse files Browse the repository at this point in the history
  • Loading branch information
Jozwiaczek committed Apr 16, 2021
1 parent cdf24b3 commit f2816de
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/prepare-release-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: 'Prepare release PR'
on:
pull_request:
branches:
- dev

jobs:
Prepare:
name: 'Prepare release pr'
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- name: 'Git checkout'
uses: actions/checkout@v2

# Beginning of yarn setup, keep in sync between all workflows
- name: Use node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2.1.5
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org/ # Needed for auth
- name: 'Use cached node_modules'
id: cache-modules
uses: actions/cache@v2.1.5
with:
path: '**/node_modules'
key: ${{ runner.os }}-v${{ matrix.node-version }}-node_modules-${{ hashFiles('yarn.lock', '**/package.json') }}
- name: 'Find location of global yarn cache'
id: yarn-cache
if: steps.cache-modules.outputs.cache-hit != 'true'
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: 'Cache global yarn cache'
uses: actions/cache@v2.1.5
if: steps.cache-modules.outputs.cache-hit != 'true'
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: 'Install dependency'
run: yarn install --frozen-lockfile
# End of yarn setup

- name: 'Build CI scripts'
run: yarn ci:build:scripts

- name: 'Prepare PR'
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const { prepareReleasePR } = require(`${process.env.GITHUB_WORKSPACE}/ci/dist/prepareReleasePR.js`)
prepareReleasePR({ github, context })
7 changes: 7 additions & 0 deletions ci/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: '../.eslintrc.js',
rules: {
'react/display-name': 0,
'no-plusplus': 0,
},
};
37 changes: 37 additions & 0 deletions ci/prepareReleasePR.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export const prepareReleasePR = async ({ github, context }: { github: any; context: any }) => {
const newMessage = `
👋 Thanks for testing#1!
`;

const commentInfo = {
...context.repo,
issue_number: context.issue.number,
};
const signature = 'via JJ GitHub Actions 🇵🇱';
const comment = {
...commentInfo,
body: `${newMessage}\n\n${signature}`,
};

let commentId;
const comments = (await github.issues.listComments(commentInfo)).data;
for (let i = comments.length; i--; ) {
const c = comments[i];
if (c.user.type === 'Bot' && c.body.includes(signature)) {
commentId = c.id;
break;
}
}

if (commentId) {
await github.issues.updateComment({
...context.repo,
comment_id: commentId,
body: comment.body,
});
}

if (!commentId) {
await github.issues.createComment(comment);
}
};
16 changes: 16 additions & 0 deletions ci/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"outDir": "dist",
"lib": ["dom", "dom.iterable", "esnext"],
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true
},
"include": ["prepareReleasePR.ts"]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"build": "lerna run build",
"check": "yarn lint:fix && yarn prettier:fix && yarn type-check && yarn test && yarn test:e2e && yarn sortPackageJson",
"ci:setup:db": "yarn ts-node ci/setupTestDatabase.ts",
"ci:build:scripts": "rimraf ci/dist && tsc --project ci/tsconfig.json",
"heroku-postbuild": "yarn install && cd packages/api && yarn typeorm-migration:run && yarn build",
"preinstall": "node -e \"if (process.env.npm_execpath.indexOf('yarn') === -1) throw new Error('Use yarn for installing')\"",
"lint": "lerna run lint",
Expand Down

0 comments on commit f2816de

Please sign in to comment.