Skip to content

Proposal: Clean up CI job a bit #727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 0 additions & 108 deletions .github/workflows/UpdateDirectory.js

This file was deleted.

83 changes: 83 additions & 0 deletions .github/workflows/UpdateDirectory.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import path from 'path'
import fs from 'fs'
import { globby } from 'globby'

const URL_BASE = 'https://github.com/TheAlgorithms/Javascript/blob/master'

function pathPrefix (i) {
if (i) {
const res = ' '.repeat(i)
return res + '*'
} else {
return '\n##'
}
}

function printPath (oldPath, newPath, output) {
const oldParts = oldPath.split(path.sep)
const newParts = newPath.split(path.sep)
for (let i = 0; i < newParts.length; ++i) {
const newPart = newParts[i]
if (i + 1 > oldParts.length || oldParts[i] !== newPart) {
if (newPart) {
output.push(`${pathPrefix(i)} ${newPart.replace('_', ' ')}`)
}
}
}
return newPath
}

function pathsToMarkdown (filePaths) {
const output = []

let oldPath = ''
filePaths.sort(function (a, b) {
if (a.toLowerCase() < b.toLowerCase()) return -1
if (a.toLowerCase() > b.toLowerCase()) return 1
return 0
})
for (let filepath of filePaths) {
const file = filepath.split(path.sep)
let filename = ''
if (file.length === 1) {
filepath = ''
filename = file[0]
} else {
const total = file.length
filename = file[total - 1]
filepath = file.splice(0, total - 1).join(path.sep)
}
if (filepath !== oldPath) {
oldPath = printPath(oldPath, filepath, output)
}
let indent = 0
for (let i = 0; i < filepath.length; ++i) {
if (filepath[i] === path.sep) {
++indent
}
}
if (filepath) {
++indent
}

// prepare the markdown-esque prefix to the file's line
const prefix = pathPrefix(indent)

// remove extension from filename
const name = filename.split('.')[0]

// create URL to the actual file on github
const url = encodeURI([URL_BASE, filepath, filename].join('/'))

output.push(`${prefix} [${name}](${url})`)
}

return output.join('\n')
}

// get paths of all .js files - excluding node_modules, the .github folder, tests and config stuff
globby(['**/*.js', '!(node_modules|.github)/**/*', '!**/*.test.js', '!babel.config.js'])
// create markdown content
.then(pathsToMarkdown)
// write markdown to file
.then(markdown => fs.writeFileSync('DIRECTORY.md', markdown + '\n', { encoding: 'utf8' }))
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Continuous Integration

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'

- name: 📦 Install dependencies
run: npm ci

- name: 🧪 Run tests
run: |
npm run doctest || true # TODO: Add all doctests
npm test

- name: 💄 Code style
run: npm run style
10 changes: 10 additions & 0 deletions .github/workflows/commitAndPushDirectory.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if ! git diff --quiet DIRECTORY.md; then
echo Changes found, attempting to commit and push...
git add DIRECTORY.md
git commit -am "Auto-update DIRECTORY.md" || true
git push --force origin HEAD:$GITHUB_REF || true
echo ... done.
else
echo No changes found, exiting.
fi

24 changes: 0 additions & 24 deletions .github/workflows/nodejs.yml

This file was deleted.

28 changes: 18 additions & 10 deletions .github/workflows/update_directory_md.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
# This GitHub Action updates the DIRECTORY.md file (if needed) when doing a git push
name: update_directory_md
name: Update Directory

on: [push]

jobs:
update_directory_md:
updateDirectory:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/setup-node@v1
- run: |
node .github/workflows/UpdateDirectory.js
cat DIRECTORY.md
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'

- name: 📦 Install dependencies
run: npm ci

- name: 🗄️ Create Directory from JS files
run: node .github/workflows/UpdateDirectory.mjs

- name: 🤓 Commit & push new Directory (if needed)
run: |
git config --global user.name github-actions
git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
git add DIRECTORY.md
git commit -am "updating DIRECTORY.md" || true
git push --force origin HEAD:$GITHUB_REF || true
.github/workflows/commitAndPushDirectory.sh
Loading