Skip to content

Commit

Permalink
chore: Update versions and add build test script (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
EmandM authored May 15, 2024
1 parent 725029d commit 7908d5b
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 31 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/external-test.yml
Original file line number Diff line number Diff line change
@@ -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
87 changes: 68 additions & 19 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
17 changes: 5 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 24 additions & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7908d5b

Please sign in to comment.