|
| 1 | +name: ci |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + pull_request: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + |
| 10 | +jobs: |
| 11 | + |
| 12 | + test_node: |
| 13 | + runs-on: ${{ matrix.os }} |
| 14 | + strategy: |
| 15 | + matrix: |
| 16 | + node: [ '15', '14', '12' ] |
| 17 | + os: [ windows-latest, ubuntu-latest ] |
| 18 | + name: Test with Node v${{ matrix.node }} on ${{ matrix.os }} |
| 19 | + steps: |
| 20 | + |
| 21 | + |
| 22 | + with: |
| 23 | + node-version: ${{ matrix.node }} |
| 24 | + - uses: bahmutov/[email protected] |
| 25 | + - run: | |
| 26 | + npm run build |
| 27 | + npm test |
| 28 | + test_deno: |
| 29 | + runs-on: ubuntu-latest |
| 30 | + name: test with Deno |
| 31 | + steps: |
| 32 | + |
| 33 | + |
| 34 | + - uses: actions/cache@v1 |
| 35 | + with: |
| 36 | + path: ~/.cache/deno |
| 37 | + key: deno-${{ runner.os }}-${{ hashFiles('deno-lock.json') }} |
| 38 | + restore-keys: | |
| 39 | + deno-${{ runner.os }}-${{ hashFiles('deno-lock.json') }} |
| 40 | + deno-${{ runner.os }}- |
| 41 | + deno- |
| 42 | + |
| 43 | + with: |
| 44 | + deno-version: v1.x |
| 45 | + - run: deno --version |
| 46 | + # We don't actually execute any runtime check but at least we make sure that, typewise, everything's fine. |
| 47 | + - uses: bahmutov/[email protected] |
| 48 | + - run: npx denoify |
| 49 | + - run: deno run --reload --unstable --no-check deno_dist/mod.ts |
| 50 | + |
| 51 | + check_if_version_upgraded: |
| 52 | + name: Check if version upgrade |
| 53 | + # We run this only if it's a push on the default branch or if it's a PR from a |
| 54 | + # branch (meaning not a PR from a fork). It would be more straightforward to test if secrets.NPM_TOKEN is |
| 55 | + # defined but GitHub Action don't allow it yet. |
| 56 | + if: | |
| 57 | + github.event_name == 'push' || |
| 58 | + github.event.pull_request.head.repo.owner.login == github.event.pull_request.base.repo.owner.login |
| 59 | + runs-on: ubuntu-latest |
| 60 | + needs: |
| 61 | + - test_node |
| 62 | + - test_deno |
| 63 | + outputs: |
| 64 | + from_version: ${{ steps.step1.outputs.from_version }} |
| 65 | + to_version: ${{ steps.step1.outputs.to_version }} |
| 66 | + is_upgraded_version: ${{ steps.step1.outputs.is_upgraded_version }} |
| 67 | + is_release_beta: ${{steps.step1.outputs.is_release_beta }} |
| 68 | + steps: |
| 69 | + - uses: garronej/[email protected] |
| 70 | + id: step1 |
| 71 | + with: |
| 72 | + action_name: is_package_json_version_upgraded |
| 73 | + branch: ${{ github.head_ref || github.ref }} |
| 74 | + |
| 75 | + publish: |
| 76 | + runs-on: ubuntu-latest |
| 77 | + needs: |
| 78 | + - check_if_version_upgraded |
| 79 | + # We create a release only if the version have been upgraded and we are on a default branch |
| 80 | + # PR on the default branch can release beta but not real release |
| 81 | + if: | |
| 82 | + needs.check_if_version_upgraded.outputs.is_upgraded_version == 'true' && |
| 83 | + ( |
| 84 | + github.event_name == 'push' || |
| 85 | + needs.check_if_version_upgraded.outputs.is_release_beta == 'true' |
| 86 | + ) |
| 87 | + steps: |
| 88 | + |
| 89 | + with: |
| 90 | + fetch-depth: 0 |
| 91 | + ref: ${{ github.ref }} |
| 92 | + - run: rm -r .github |
| 93 | + - run: | |
| 94 | + git branch -d latest || true |
| 95 | + git push origin :latest || true |
| 96 | + - run: | |
| 97 | + git branch latest |
| 98 | + git checkout latest |
| 99 | + |
| 100 | + with: |
| 101 | + node-version: '15' |
| 102 | + registry-url: https://registry.npmjs.org/ |
| 103 | + - uses: bahmutov/[email protected] |
| 104 | + - run: npm run build |
| 105 | + - run: npx -y -p [email protected] enable_short_npm_import_path |
| 106 | + env: |
| 107 | + DRY_RUN: "0" |
| 108 | + - run: | |
| 109 | + if [ "$(npm show . version)" = "$VERSION" ]; then |
| 110 | + echo "This version is already published" |
| 111 | + exit 0 |
| 112 | + fi |
| 113 | + if [ "$NODE_AUTH_TOKEN" = "" ]; then |
| 114 | + echo "Can't publish on NPM, You must first create a secret called NPM_TOKEN that contains your NPM auth token. " |
| 115 | + false |
| 116 | + fi |
| 117 | + npm publish |
| 118 | + env: |
| 119 | + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} |
| 120 | + VERSION: ${{ needs.check_if_version_upgraded.outputs.to_version }} |
| 121 | + - run: | |
| 122 | + git config --global user.name "actions" |
| 123 | + git config --global user.email [email protected] |
| 124 | + git add -A |
| 125 | + git commit -am "Enabling shorter import paths" |
| 126 | + git push origin latest |
| 127 | + - uses: softprops/action-gh-release@v1 |
| 128 | + with: |
| 129 | + name: Release v${{ needs.check_if_version_upgraded.outputs.to_version }} |
| 130 | + tag_name: v${{ needs.check_if_version_upgraded.outputs.to_version }} |
| 131 | + target_commitish: latest |
| 132 | + generate_release_notes: true |
| 133 | + draft: false |
| 134 | + prerelease: ${{ needs.check_if_version_upgraded.outputs.is_release_beta == 'true' }} |
| 135 | + env: |
| 136 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 137 | + |
0 commit comments