feature/ruby-runner
claude/smbcloud-github-app-k9641p
development
feature/apps
feature/build-release
feature/ci-docs
feature/ci-ruby-gems
feature/cicd
feature/completion
feature/dist-nuget
feature/fix-ci-sdk-pypi-rubygem
feature/fix-clippy-on-stable-channel
feature/fix-deployment-script
feature/github-email
feature/gresiq-v1
feature/project-new-structure
feature/rsync-deploy
feature/ruby-runner
feature/sdk-npm
feature/sdk-workflows
feature/smbcloud-cli-release-npm
feature/smbcloud-deploy
feature/wasm
main
release/v0.7.4
| 1 | name: Publish to npm |
| 2 | |
| 3 | on: |
| 4 | push: |
| 5 | tags: |
| 6 | - "v*.*.*" |
| 7 | |
| 8 | env: |
| 9 | SMB_CLIENT_ID: ${{ secrets.SMB_CLIENT_ID }} |
| 10 | SMB_CLIENT_SECRET: ${{ secrets.SMB_CLIENT_SECRET }} |
| 11 | SMB_API_HOST: ${{ secrets.SMB_API_HOST }} |
| 12 | SMB_API_PROTOCOL: ${{ secrets.SMB_API_PROTOCOL }} |
| 13 | GH_OAUTH_CLIENT_ID: ${{ secrets.GH_OAUTH_CLIENT_ID }} |
| 14 | GH_OAUTH_CLIENT_SECRET: ${{ secrets.GH_OAUTH_CLIENT_SECRET }} |
| 15 | GH_OAUTH_REDIRECT_HOST: ${{ secrets.GH_OAUTH_REDIRECT_HOST }} |
| 16 | GH_OAUTH_REDIRECT_PORT: ${{ secrets.GH_OAUTH_REDIRECT_PORT }} |
| 17 | |
| 18 | jobs: |
| 19 | publish-npm-binaries: |
| 20 | name: Publish NPM packages |
| 21 | runs-on: ${{ matrix.build.os }} |
| 22 | strategy: |
| 23 | fail-fast: false |
| 24 | matrix: |
| 25 | build: |
| 26 | - { |
| 27 | NAME: linux-x64-glibc, |
| 28 | OS: ubuntu-20.04, |
| 29 | TOOLCHAIN: stable, |
| 30 | TARGET: x86_64-unknown-linux-gnu, |
| 31 | } |
| 32 | # Cannot cross-compile for now |
| 33 | #- { |
| 34 | # NAME: linux-arm64-glibc, |
| 35 | # OS: ubuntu-20.04, |
| 36 | # TOOLCHAIN: stable, |
| 37 | # TARGET: aarch64-unknown-linux-gnu, |
| 38 | # } |
| 39 | - { |
| 40 | NAME: win32-x64-msvc, |
| 41 | OS: windows-2022, |
| 42 | TOOLCHAIN: stable, |
| 43 | TARGET: x86_64-pc-windows-msvc, |
| 44 | } |
| 45 | - { |
| 46 | NAME: win32-arm64-msvc, |
| 47 | OS: windows-2022, |
| 48 | TOOLCHAIN: stable, |
| 49 | TARGET: aarch64-pc-windows-msvc, |
| 50 | } |
| 51 | - { |
| 52 | NAME: darwin-x64, |
| 53 | OS: macos-11, |
| 54 | TOOLCHAIN: stable, |
| 55 | TARGET: x86_64-apple-darwin, |
| 56 | } |
| 57 | - { |
| 58 | NAME: darwin-arm64, |
| 59 | OS: macos-11, |
| 60 | TOOLCHAIN: stable, |
| 61 | TARGET: aarch64-apple-darwin, |
| 62 | } |
| 63 | steps: |
| 64 | - name: Checkout |
| 65 | uses: actions/checkout@v3 |
| 66 | |
| 67 | - name: Set the release version |
| 68 | shell: bash |
| 69 | run: echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV |
| 70 | |
| 71 | - name: Install toolkit |
| 72 | uses: dtolnay/rust-toolchain@master |
| 73 | with: |
| 74 | targets: ${{ matrix.build.TARGET }} |
| 75 | toolchain: ${{ matrix.build.TOOLCHAIN}} |
| 76 | |
| 77 | - name: Build |
| 78 | env: |
| 79 | GH_OAUTH_CLIENT_ID: ${{ secrets.GH_OAUTH_CLIENT_ID }} |
| 80 | GH_OAUTH_CLIENT_SECRET: ${{ secrets.GH_OAUTH_CLIENT_SECRET }} |
| 81 | GH_OAUTH_REDIRECT_URI: ${{ secrets.GH_OAUTH_REDIRECT_URI }} |
| 82 | shell: bash |
| 83 | run: | |
| 84 | cargo build --release --locked --target ${{ matrix.build.TARGET }} |
| 85 | |
| 86 | - name: Install node |
| 87 | uses: actions/setup-node@v3 |
| 88 | with: |
| 89 | node-version: "18" |
| 90 | registry-url: "https://registry.npmjs.org" |
| 91 | |
| 92 | - name: Publish to NPM |
| 93 | shell: bash |
| 94 | run: | |
| 95 | # We want to name our npm package @smbcloud/cli, but the main command is smb. |
| 96 | # This is the tricky part. All the optional dependencies should follow the naming convention. |
| 97 | # So, we will generate @smbcloud/cli-${matrix.build.TARGET} |
| 98 | |
| 99 | # Move to the npm directory |
| 100 | cd npm |
| 101 | # set the binary name, this is from the rust Cargo.toml file |
| 102 | cargo_bin="smb" |
| 103 | node_pkg_prefix="cli" |
| 104 | # derive the OS and architecture from the build matrix name |
| 105 | # note: when split by a hyphen, first part is the OS and the second is the architecture |
| 106 | node_os=$(echo "${{ matrix.build.NAME }}" | cut -d '-' -f1) |
| 107 | export node_os |
| 108 | node_arch=$(echo "${{ matrix.build.NAME }}" | cut -d '-' -f2) |
| 109 | export node_arch |
| 110 | # set the version |
| 111 | export node_version="${{ env.RELEASE_VERSION }}" |
| 112 | # set the package name |
| 113 | # note: use 'windows' as OS name instead of 'win32' |
| 114 | if [ "${{ matrix.build.OS }}" = "windows-2022" ]; then |
| 115 | export node_pkg="${node_pkg_prefix}-windows-${node_arch}" |
| 116 | else |
| 117 | export node_pkg="${node_pkg_prefix}-${node_os}-${node_arch}" |
| 118 | fi |
| 119 | # create the package directory |
| 120 | mkdir -p "${node_pkg}/bin" |
| 121 | # generate package.json from the template |
| 122 | envsubst < package.json.tmpl > "${node_pkg}/package.json" |
| 123 | # generate readme.md from the template |
| 124 | envsubst < README.md.tmpl > "${node_pkg}/README.md" |
| 125 | # copy the binary into the package |
| 126 | # note: windows binaries has '.exe' extension |
| 127 | if [ "${{ matrix.build.OS }}" = "windows-2022" ]; then |
| 128 | cargo_bin="${cargo_bin}.exe" |
| 129 | fi |
| 130 | cp "../target/${{ matrix.build.TARGET }}/release/${cargo_bin}" "${node_pkg}/bin" |
| 131 | # publish the package |
| 132 | cd "${node_pkg}" |
| 133 | npm publish --access public |
| 134 | env: |
| 135 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 136 | |
| 137 | publish-npm-base: |
| 138 | name: Publish the base NPM package |
| 139 | needs: publish-npm-binaries |
| 140 | runs-on: ubuntu-20.04 |
| 141 | steps: |
| 142 | - name: Checkout |
| 143 | uses: actions/checkout@v3 |
| 144 | |
| 145 | - name: Set the release version |
| 146 | shell: bash |
| 147 | run: echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV |
| 148 | |
| 149 | - name: Install node |
| 150 | uses: actions/setup-node@v3 |
| 151 | with: |
| 152 | node-version: "18" |
| 153 | registry-url: "https://registry.npmjs.org" |
| 154 | |
| 155 | - name: Publish the package |
| 156 | shell: bash |
| 157 | run: | |
| 158 | cd npm/smbcloud-cli |
| 159 | |
| 160 | # set the version |
| 161 | export release_version="${{ env.RELEASE_VERSION }}" |
| 162 | |
| 163 | # use the tag version |
| 164 | envsubst < ../package-main.json.tmpl > "./package.json" |
| 165 | |
| 166 | yarn install # requires optional dependencies to be present in the registry |
| 167 | yarn build |
| 168 | npm publish --access public |
| 169 | env: |
| 170 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |