├── README.md └── .github └── workflows ├── lint.yaml ├── update-doc.yaml └── publish.yaml /README.md: -------------------------------------------------------------------------------- 1 | # GITHUB WORKFLOW FOR Hodfords Opensource 2 | 3 | This is a github workflow for Hodfords Opensource. It will run the test and build the project. 4 | -------------------------------------------------------------------------------- /.github/workflows/lint.yaml: -------------------------------------------------------------------------------- 1 | name: NPM lint 2 | 3 | on: 4 | workflow_call: 5 | 6 | jobs: 7 | lint: 8 | runs-on: ubuntu-latest 9 | container: node:22 10 | steps: 11 | - uses: actions/checkout@v4 12 | - run: npm install 13 | - run: npm run lint 14 | -------------------------------------------------------------------------------- /.github/workflows/update-doc.yaml: -------------------------------------------------------------------------------- 1 | name: Update Document 2 | on: 3 | workflow_call: 4 | secrets: 5 | DOC_SSH_PRIVATE_KEY: 6 | required: true 7 | jobs: 8 | update-docs: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v4 12 | - uses: actions/setup-node@v4 13 | with: 14 | node-version: '22.x' 15 | - name: Set up SSH 16 | env: 17 | DOC_SSH_PRIVATE_KEY: ${{ secrets.DOC_SSH_PRIVATE_KEY }} 18 | run: | 19 | mkdir -p ~/.ssh 20 | echo $DOC_SSH_PRIVATE_KEY | base64 -d > ~/.ssh/id_ed25519 21 | chmod 700 ~/.ssh 22 | chmod 400 ~/.ssh/id_ed25519 23 | eval $(ssh-agent -s) 24 | ssh-add ~/.ssh/id_ed25519 25 | git config --global user.email "actions@github.com" 26 | git config --global user.name "GitHub Actions" 27 | - name: Clone docs repository 28 | run: | 29 | git clone git@github.com:hodfords-solutions/docs.git docs-repo 30 | cd docs-repo 31 | git checkout main 32 | cd ../ 33 | 34 | - name: Update README file 35 | run: | 36 | export LIB_NAME=$(node -p "require('./package.json').name.replace('@hodfords/', '')") 37 | export LIB_FULL_NAME=$(node -p "require('./package.json').name") 38 | echo -e "---\ndisplayed_sidebar: docs\ntitle: \"$LIB_FULL_NAME\"\n---" | cat - README.md > temp && mv temp README.md 39 | mkdir -p docs-repo/pages/$LIB_NAME 40 | cp README.md docs-repo/pages/$LIB_NAME/index.md 41 | if ! grep -q "$LIB_NAME" docs-repo/.page; then 42 | echo "$LIB_NAME" >> docs-repo/.page 43 | fi 44 | 45 | - name: Commit and Push changes 46 | shell: sh 47 | run: | 48 | export LIB_NAME=$(node -p "require('./package.json').name.replace('@hodfords/', '')") 49 | cd docs-repo 50 | 51 | export GIT_CHANGE=$(git status --porcelain) 52 | if [ -z "$GIT_CHANGE" ]; then 53 | echo "No changes" 54 | else 55 | git add . 56 | git commit -m "Update docs for $LIB_NAME: ${{ github.event.head_commit.message }}" 57 | git push 58 | fi 59 | -------------------------------------------------------------------------------- /.github/workflows/publish.yaml: -------------------------------------------------------------------------------- 1 | name: Build and Publish Library 2 | on: 3 | workflow_call: 4 | inputs: 5 | build_path: 6 | description: 'Path to the library to build' 7 | required: false 8 | default: 'dist/libs' 9 | type: string 10 | package_path: 11 | description: 'Path to the package.json directory' 12 | required: false 13 | default: './' 14 | type: string 15 | secrets: 16 | NPM_TOKEN: 17 | required: true 18 | jobs: 19 | check-package: 20 | runs-on: ubuntu-latest 21 | container: node:22 22 | permissions: 23 | packages: write 24 | contents: read 25 | outputs: 26 | packageExists: ${{ steps.check.outputs.packageExists }} 27 | steps: 28 | - uses: actions/checkout@v4 29 | - uses: actions/setup-node@v4 30 | with: 31 | node-version: '22.x' 32 | - run: | 33 | cd ${{ inputs.package_path }} 34 | npm install 35 | - name: Check if package is published 36 | run: | 37 | cd ${{ inputs.package_path }} 38 | if [ "$(npm view $(node -p "require('./package.json').name")@$(node -p "require('./package.json').version") version)" = "$(node -p "require('./package.json').version")" ]; then 39 | echo "packageExists=True" >> $GITHUB_OUTPUT 40 | else 41 | echo "packageExists=False" >> $GITHUB_OUTPUT 42 | fi 43 | id: check 44 | build: 45 | needs: check-package 46 | container: node:22 47 | if: ${{ needs.check-package.outputs.packageExists == 'False' }} 48 | runs-on: ubuntu-latest 49 | env: 50 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 51 | steps: 52 | - uses: actions/checkout@v4 53 | - run: | 54 | cd ${{ inputs.package_path }} 55 | npm install 56 | - run: | 57 | cd ${{ inputs.package_path }} 58 | npm run build 59 | - run: | 60 | cd ${{ inputs.package_path }} 61 | export CURRENT_PATH=$(pwd) 62 | IFS=';' read -ra ADDR <<< "${{ inputs.build_path }}" 63 | for i in "${ADDR[@]}"; do 64 | cd $CURRENT_PATH/$i && npm publish --access public 65 | done 66 | shell: bash 67 | --------------------------------------------------------------------------------