Assert version dynamically in test suite instead of hardcoded v1.0.0 #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: GitHub Packages | |
| on: | |
| push: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| jobs: | |
| # ============================================ | |
| # PUBLISH TO GITHUB PACKAGES | |
| # ============================================ | |
| publish-gpr: | |
| name: Publish to GitHub Packages | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: ./cloudsync-cli | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| registry-url: 'https://npm.pkg.github.com' | |
| scope: '@tech4file' | |
| cache: 'npm' | |
| cache-dependency-path: cloudsync-cli/package-lock.json | |
| - name: Configure npm for GitHub Packages | |
| run: | | |
| cat <<EOF > ~/.npmrc | |
| @tech4file:registry=https://npm.pkg.github.com | |
| //npm.pkg.github.com/:_authToken=\${NODE_AUTH_TOKEN} | |
| EOF | |
| - name: Get version | |
| id: version | |
| run: | | |
| if [[ "${{ github.event_name }}" == "push" ]]; then | |
| echo "VERSION=$(jq -r .version package.json)" >> $GITHUB_OUTPUT | |
| else | |
| echo "VERSION=1.0.0" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Update package name for GitHub Packages | |
| run: | | |
| npm pkg set name="@tech4file/cloudsync-cli" | |
| npm pkg set publishConfig.registry="https://npm.pkg.github.com" | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run tests | |
| run: npm test | |
| - name: Publish to GitHub Packages | |
| run: npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # ============================================ | |
| # VERIFY PUBLISHED PACKAGE | |
| # ============================================ | |
| verify-gpr: | |
| name: Verify Published Package | |
| runs-on: ubuntu-latest | |
| needs: [publish-gpr] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| registry-url: 'https://npm.pkg.github.com' | |
| scope: '@tech4file' | |
| - name: Install published package | |
| run: | | |
| sleep 15 | |
| npm install -g @tech4file/cloudsync-cli | |
| cloudsync --version | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Test installed package | |
| run: | | |
| cloudsync doctor | |
| cloudsync --help | head -20 |