diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 8f7fe5b..2f2a1f1 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -11,14 +11,43 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Set env + run: | + echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + - name: Print Version + run: | + echo $VERSION + echo ${{ env.VERSION }} - run: npm ci - run: npm run build - # Run Integration tests for the API code - - run: npm run test --username=${{ secrets.API_USERNAME }} --password=${{ secrets.API_PASSWORD }} + # Step to retrieve the bearer token + - name: Retrieve bearer token + id: get_bearer_token + run: | + response=$(curl -X POST ${{secrets.OKTA_ACCESS_TOKEN_URL}}/connect/token \ + -H "Content-Type: application/x-www-form-urlencoded" \ + -d "grant_type=client_credentials&client_id=${{secrets.OKTA_CLIENT_ID}}&client_secret=${{secrets.OKTA_CLIENT_SECRET}}") + token=$(echo $response | jq -r '.access_token') + echo "BEARER_TOKEN=${token}" >> $GITHUB_ENV + + # Use the bearer token as an environment variable in the npm test command + - name: Run npm test with bearer token + run: npm run test + env: + BEARER_TOKEN: ${{ env.BEARER_TOKEN }} - uses: actions/setup-node@v2 with: node-version: 16 - registry-url: 'https://registry.npmjs.org' + registry-url: "https://registry.npmjs.org" + - name: Update package.json version + run: | + jq --arg version "$VERSION" '.version = $version' package.json > temp.json && mv temp.json package.json + - name: Update resources + uses: test-room-7/action-update-file@v1 + with: + file-path: ./package.json + commit-msg: Commit npm package version + github-token: ${{ secrets.GITHUB_TOKEN }} - run: cp ./README.md ./dist/README.md - run: cp ./package.json ./dist/package.json - run: npm publish ./dist