diff --git a/.github/workflows/external-test.yml b/.github/workflows/external-test.yml new file mode 100644 index 0000000..1248c98 --- /dev/null +++ b/.github/workflows/external-test.yml @@ -0,0 +1,46 @@ +name: Test Package External +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + external_test: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-node@v4 + + - name: Checkout code + uses: actions/checkout@v4 + with: + path: build-tar + + - run: npm ci + working-directory: build-tar + + - run: npm run build + working-directory: build-tar + + - id: pack_tar + run: echo "tar_name=$(npm pack)" >> $GITHUB_OUTPUT + working-directory: build-tar + + - uses: actions/checkout@v4 + with: + repository: EmandM/import-test + path: external-test + + - run: npm ci + working-directory: external-test + + - run: npm uninstall ts-mock-imports # Ensure no contamination from existing + working-directory: external-test + + - run: npm install ${{ github.workspace }}/build-tar/${{ steps.pack_tar.outputs.tar_name }} + working-directory: external-test + + - run: npm test + working-directory: external-test diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ad376aa..1e667ce 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,44 +1,79 @@ name: Publish Packages -on: +on: release: - types: [created] - workflow_dispatch: + types: [published] + jobs: - build: + verify: runs-on: ubuntu-latest + outputs: + do_dry_run: ${{ steps.variables.outputs.is_dry_run }} + environment: ${{ steps.variables.outputs.env }} + npm_package_version: ${{ steps.set_version.outputs.version }} steps: - - uses: actions/checkout@v1 - - uses: actions/setup-node@v1 - with: - node-version: 12 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 - run: npm ci - run: npm run build - run: npm run lint - run: npm test + - id: variables + run: | + echo "env=dry-run" >> $GITHUB_OUTPUT + echo "is_dry_run=--dry-run" >> $GITHUB_OUTPUT + echo "current_version=$(npm show ts-mock-imports version)" >> $GITHUB_OUTPUT + if [[ "${{ github.event_name }}" == "release" ]]; then + echo "env=production" >> $GITHUB_OUTPUT + echo "is_dry_run=" >> $GITHUB_OUTPUT + fi + - id: semver + uses: matt-usurp/validate-semver@v2 + with: + version: ${{ github.event.release.tag_name }} + - id: set_version + run: echo "version=${{ steps.semver.outputs.version }}" >> $GITHUB_OUTPUT + - run: echo "Creating release for ts-mock-imports at version ${{ steps.semver.outputs.version }} with ${{ steps.variables.outputs.is_dry_run }}. Current version is ${{ steps.variables.outputs.current_version }}." + + update_version: + runs-on: ubuntu-latest + needs: verify + environment: ${{ needs.verify.outputs.environment }} + if: ${{ needs.verify.outputs.environment == 'production' }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + - run: | + date > generated.txt + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + npm version ${{ needs.verify.outputs.npm_package_version }} + git push && git push --tags + publish-npm: - needs: build + needs: [verify, update_version] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - run: echo ${{ needs.verify.outputs.do_dry_run }} + - uses: actions/checkout@v4 # Setup .npmrc file to publish to npm - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v4 with: - node-version: '12' registry-url: 'https://registry.npmjs.org' - run: npm ci - run: npm run compile # Publish to npm - - run: npm publish --access public + - run: npm publish --access public ${{ needs.verify.outputs.do_dry_run }} --dry-run env: NODE_AUTH_TOKEN: ${{ secrets.PUBLISH_NPM_TOKEN }} + publish-gpr: - needs: build + needs: [verify, update_version] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - uses: actions/setup-node@v1 + - run: echo ${{ needs.verify.outputs.do_dry_run }} + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: - node-version: 12 registry-url: https://npm.pkg.github.com/ scope: '@emandm' # Publish to GitHub Packages @@ -51,6 +86,20 @@ jobs: cat package.json - run: echo registry=https://npm.pkg.github.com/emandm >> .npmrc - - run: npm publish + - run: npm publish ${{ needs.verify.outputs.do_dry_run }} --dry-run env: - NODE_AUTH_TOKEN: ${{ secrets.PUBLISH_GITHUB_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + external_test: + runs-on: ubuntu-latest + needs: [verify, publish-npm] + steps: + - uses: actions/setup-node@v4 + - uses: actions/checkout@v4 + with: + repository: EmandM/import-test + + - run: npm ci + - run: npm uninstall ts-mock-imports # Ensure no contamination from existing + - run: npm install ts-mock-imports@${{ needs.verify.outputs.npm_package_version }} + - run: npm test diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b4d2210..37ec0a0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,20 +9,13 @@ on: - main jobs: - build: + test: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: latest - - - name: Install dependencies - run: npm install + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + - run: npm ci - name: Run Tests - run: npm run test + run: npm test diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml new file mode 100644 index 0000000..0128f89 --- /dev/null +++ b/.github/workflows/verify.yml @@ -0,0 +1,24 @@ +name: Verify Code Quality +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + - run: npm ci + - run: npm run lint + compile: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + - run: npm ci + - run: npm run build