|
| 1 | +name: NPM publish |
| 2 | +on: workflow_dispatch |
| 3 | + |
| 4 | +jobs: |
| 5 | + build: |
| 6 | + name: Build |
| 7 | + runs-on: ubuntu-latest |
| 8 | + steps: |
| 9 | + - name: Checkout sources |
| 10 | + uses: actions/checkout@v4 |
| 11 | + - name: Use Node.js 18.x.x |
| 12 | + uses: actions/setup-node@v4 |
| 13 | + with: |
| 14 | + node-version: 18 |
| 15 | + - name: Installing dependencies |
| 16 | + run: npm ci |
| 17 | + - name: Building sources |
| 18 | + run: npm run build |
| 19 | + |
| 20 | + lint: |
| 21 | + name: Lint Code |
| 22 | + needs: build |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: Checkout sources |
| 26 | + uses: actions/checkout@v4 |
| 27 | + - name: Use Node.js 18.x.x |
| 28 | + uses: actions/setup-node@v4 |
| 29 | + with: |
| 30 | + node-version: 18 |
| 31 | + - name: Installing dependencies |
| 32 | + run: npm ci |
| 33 | + - name: Linting |
| 34 | + run: npm run lint |
| 35 | + env: |
| 36 | + CI: true |
| 37 | + |
| 38 | + test_unit: |
| 39 | + name: Unit Tests |
| 40 | + needs: build |
| 41 | + runs-on: ubuntu-latest |
| 42 | + steps: |
| 43 | + - name: Checkout sources |
| 44 | + uses: actions/checkout@v4 |
| 45 | + - name: Use Node.js 18.x.x |
| 46 | + uses: actions/setup-node@v4 |
| 47 | + with: |
| 48 | + node-version: 18 |
| 49 | + - name: Installing dependencies |
| 50 | + run: npm ci |
| 51 | + - name: Running unit tests |
| 52 | + run: npm run test:unit |
| 53 | + |
| 54 | + test_integration: |
| 55 | + name: Integration Tests |
| 56 | + needs: |
| 57 | + - lint |
| 58 | + - test_unit |
| 59 | + runs-on: ubuntu-latest |
| 60 | + steps: |
| 61 | + - name: Checkout sources |
| 62 | + uses: actions/checkout@v4 |
| 63 | + - name: Use Node.js 18.x.x |
| 64 | + uses: actions/setup-node@v4 |
| 65 | + with: |
| 66 | + node-version: 18 |
| 67 | + - name: Installing dependencies |
| 68 | + run: npm ci |
| 69 | + - name: Creating `.env` file |
| 70 | + run: | |
| 71 | + touch .env |
| 72 | + echo HOST=${{ secrets.HOST }} >> .env |
| 73 | + echo EMAIL=${{ secrets.EMAIL }} >> .env |
| 74 | + echo API_TOKEN=${{ secrets.API_TOKEN }} >> .env |
| 75 | + - name: Running integration tests |
| 76 | + run: npm run test:integration |
| 77 | + |
| 78 | + publish: |
| 79 | + name: Package publish |
| 80 | + needs: |
| 81 | + - test_integration |
| 82 | + runs-on: ubuntu-latest |
| 83 | + steps: |
| 84 | + - name: Checkout sources |
| 85 | + uses: actions/checkout@v4 |
| 86 | + - name: Use Node.js 18.x.x |
| 87 | + uses: actions/setup-node@v4 |
| 88 | + with: |
| 89 | + node-version: 18 |
| 90 | + registry-url: 'https://registry.npmjs.org' |
| 91 | + - name: Installing dependencies |
| 92 | + run: npm ci |
| 93 | + - name: Building sources |
| 94 | + run: npm run build |
| 95 | + - name: Publishing |
| 96 | + run: npm publish |
| 97 | + env: |
| 98 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 99 | + |
| 100 | + publish-docs: |
| 101 | + name: Docs publish |
| 102 | + needs: |
| 103 | + - publish |
| 104 | + runs-on: ubuntu-latest |
| 105 | + steps: |
| 106 | + - name: Checkout code |
| 107 | + uses: actions/checkout@v4 |
| 108 | + with: |
| 109 | + ref: master |
| 110 | + - name: Use Node.js 18.x.x |
| 111 | + uses: actions/setup-node@v4 |
| 112 | + with: |
| 113 | + node-version: 18 |
| 114 | + - name: Installing dependencies |
| 115 | + run: npm ci |
| 116 | + - name: Generate docs |
| 117 | + run: npm run doc |
| 118 | + - name: Extract version |
| 119 | + id: pkg |
| 120 | + run: echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV |
| 121 | + - name: Checkout docs branch |
| 122 | + uses: actions/checkout@v4 |
| 123 | + with: |
| 124 | + ref: docs |
| 125 | + clean: false |
| 126 | + - name: Copy docs to root |
| 127 | + run: | |
| 128 | + cp -r docs/* . |
| 129 | + - name: Commit and push docs |
| 130 | + run: | |
| 131 | + git config user.name "GitHub Actions" |
| 132 | + git config user.email "actions@github.com" |
| 133 | + git add . |
| 134 | + git commit -m "Update documentation for version v${{ env.VERSION }}" |
| 135 | + git push |
| 136 | +
|
| 137 | + creating-git-tag: |
| 138 | + name: Create Git Tag |
| 139 | + needs: |
| 140 | + - publish |
| 141 | + runs-on: ubuntu-latest |
| 142 | + steps: |
| 143 | + - name: Checkout sources |
| 144 | + uses: actions/checkout@v4 |
| 145 | + - name: Use Node.js 18.x.x |
| 146 | + uses: actions/setup-node@v4 |
| 147 | + with: |
| 148 | + node-version: 18 |
| 149 | + - name: Extract version from package.json |
| 150 | + run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_ENV |
| 151 | + - name: Create and Push Git Tag |
| 152 | + run: | |
| 153 | + git config user.name "GitHub Actions" |
| 154 | + git config user.email "actions@github.com" |
| 155 | + TAG="v${{ env.version }}" |
| 156 | + git tag $TAG |
| 157 | + git push origin $TAG |
| 158 | +
|
| 159 | + creating-github-release: |
| 160 | + name: Create GitHub Release |
| 161 | + needs: |
| 162 | + - creating-git-tag |
| 163 | + runs-on: ubuntu-latest |
| 164 | + steps: |
| 165 | + - name: Checkout sources |
| 166 | + uses: actions/checkout@v4 |
| 167 | + - name: Use Node.js 18.x.x |
| 168 | + uses: actions/setup-node@v4 |
| 169 | + with: |
| 170 | + node-version: 18 |
| 171 | + - name: Extract version from package.json |
| 172 | + run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_ENV |
| 173 | + - name: Extract Changelog Entry |
| 174 | + id: changelog |
| 175 | + uses: juliangruber/read-file-action@v1 |
| 176 | + with: |
| 177 | + path: ./CHANGELOG.md |
| 178 | + - name: Parse Changelog Entry |
| 179 | + run: | |
| 180 | + CHANGELOG_CONTENT=$(awk '/^### [0-9]+\.[0-9]+\.[0-9]+/ {if (p) exit; p=1} p' CHANGELOG.md) |
| 181 | + # Sanitize changelog content |
| 182 | + CHANGELOG_CONTENT=$(echo "$CHANGELOG_CONTENT" | sed ':a;N;$!ba;s/\r//g; s/\n/\\n/g') |
| 183 | + echo "CHANGELOG=$CHANGELOG_CONTENT" >> $GITHUB_ENV |
| 184 | + - name: Create GitHub Release |
| 185 | + uses: softprops/action-gh-release@v1 |
| 186 | + with: |
| 187 | + tag_name: v${{ env.version }} |
| 188 | + name: Release v${{ env.version }} |
| 189 | + body: ${{ env.CHANGELOG }} |
0 commit comments