|
| 1 | +name: "ndc-nodejs-lambda connector" |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + - test-ci/** |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - 'main' |
| 10 | + - test-ci/** |
| 11 | + tags: |
| 12 | + - v** |
| 13 | + |
| 14 | +env: |
| 15 | + DOCKER_REGISTRY: ghcr.io |
| 16 | + DOCKER_IMAGE_NAME: hasura/ndc-nodejs-lambda |
| 17 | + |
| 18 | +jobs: |
| 19 | + build-npm: |
| 20 | + name: Build ndc-lambda-sdk npm package |
| 21 | + defaults: |
| 22 | + run: |
| 23 | + working-directory: ./ndc-lambda-sdk |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + - uses: actions/setup-node@v4 |
| 28 | + with: |
| 29 | + node-version-file: .nvmrc |
| 30 | + registry-url: https://registry.npmjs.org |
| 31 | + cache: npm |
| 32 | + cache-dependency-path: ./ndc-lambda-sdk/package-lock.json |
| 33 | + - run: npm ci |
| 34 | + - run: npm run build |
| 35 | + - run: npm test |
| 36 | + |
| 37 | + publish-npm: |
| 38 | + name: Publish ndc-lambda-sdk to npm |
| 39 | + defaults: |
| 40 | + run: |
| 41 | + working-directory: ./ndc-lambda-sdk |
| 42 | + needs: build-npm |
| 43 | + runs-on: ubuntu-latest |
| 44 | + if: ${{ startsWith(github.ref, 'refs/tags/v') }} |
| 45 | + steps: |
| 46 | + - uses: actions/checkout@v4 |
| 47 | + - uses: actions/setup-node@v4 |
| 48 | + with: |
| 49 | + node-version-file: .nvmrc |
| 50 | + registry-url: https://registry.npmjs.org |
| 51 | + cache: npm |
| 52 | + cache-dependency-path: ./ndc-lambda-sdk/package-lock.json |
| 53 | + - run: | |
| 54 | + PACKAGE_VERSION=`npm version | sed -rn "2 s/.*: '([^']*)'.*/\1/g; 2 p"` |
| 55 | + TAG=`echo "$GITHUB_REF"| sed -r "s#.*/##g"` |
| 56 | + echo '$TAG' = "$TAG" |
| 57 | + echo '$GITHUB_REF' = "$GITHUB_REF" |
| 58 | + echo '$PACKAGE_VERSION' = "$PACKAGE_VERSION" |
| 59 | + if [ "$TAG" = "v$PACKAGE_VERSION" ] |
| 60 | + then |
| 61 | + echo "Success! Versions match." |
| 62 | + else |
| 63 | + echo "Package version (v$PACKAGE_VERSION) must match tag (GITHUB_REF: $GITHUB_REF) in order to publish" 1>&2 |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | + - run: npm ci |
| 67 | + - run: npm run build |
| 68 | + - run: npm publish --access public |
| 69 | + env: |
| 70 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 71 | + |
| 72 | + docker: |
| 73 | + name: Build base docker image |
| 74 | + runs-on: ubuntu-latest |
| 75 | + steps: |
| 76 | + - uses: actions/checkout@v4 |
| 77 | + - uses: docker/login-action@v3 |
| 78 | + with: |
| 79 | + registry: ${{ env.DOCKER_REGISTRY }} |
| 80 | + username: ${{ github.actor }} |
| 81 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + - name: Extract metadata (tags, labels) for Docker |
| 83 | + id: docker-metadata |
| 84 | + uses: docker/metadata-action@v5 |
| 85 | + with: |
| 86 | + images: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE_NAME }} |
| 87 | + - uses: docker/build-push-action@v5 |
| 88 | + with: |
| 89 | + context: . |
| 90 | + push: ${{ startsWith(github.ref, 'refs/tags/v') }} |
| 91 | + tags: ${{ steps.docker-metadata.outputs.tags }} |
| 92 | + labels: ${{ steps.docker-metadata.outputs.labels }} |
| 93 | + |
| 94 | + release-connector: |
| 95 | + name: Release connector |
| 96 | + defaults: |
| 97 | + run: |
| 98 | + working-directory: ./connector-definition |
| 99 | + runs-on: ubuntu-latest |
| 100 | + needs: |
| 101 | + - publish-npm |
| 102 | + - docker |
| 103 | + if: ${{ startsWith(github.ref, 'refs/tags/v') }} |
| 104 | + steps: |
| 105 | + - uses: actions/checkout@v4 |
| 106 | + - uses: actions/setup-node@v4 |
| 107 | + with: |
| 108 | + node-version-file: .nvmrc |
| 109 | + registry-url: https://registry.npmjs.org |
| 110 | + cache: npm |
| 111 | + cache-dependency-path: ./ndc-lambda-sdk/package-lock.json |
| 112 | + - name: Build connector definition |
| 113 | + run: make build |
| 114 | + - uses: actions/upload-artifact@v4 |
| 115 | + with: |
| 116 | + name: connector-definition.tgz |
| 117 | + path: ./connector-definition/dist/connector-definition.tgz |
| 118 | + compression-level: 0 # Already compressed |
| 119 | + - name: Get version from tag |
| 120 | + id: get-version |
| 121 | + run: | |
| 122 | + echo "tagged_version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT |
| 123 | + shell: bash |
| 124 | + - uses: mindsers/changelog-reader-action@v2 |
| 125 | + id: changelog-reader |
| 126 | + with: |
| 127 | + version: ${{ steps.get-version.outputs.tagged_version }} |
| 128 | + path: ./CHANGELOG.md |
| 129 | + - uses: softprops/action-gh-release@v1 |
| 130 | + with: |
| 131 | + draft: false |
| 132 | + tag_name: v${{ steps.get-version.outputs.tagged_version }} |
| 133 | + body: ${{ steps.changelog-reader.outputs.changes }} |
| 134 | + files: | |
| 135 | + ./connector-definition/dist/connector-definition.tgz |
| 136 | + fail_on_unmatched_files: true |
0 commit comments