diff --git a/.github/actions/anchor-install/action.yml b/.github/actions/anchor-install/action.yml new file mode 100644 index 0000000..e2d833f --- /dev/null +++ b/.github/actions/anchor-install/action.yml @@ -0,0 +1,36 @@ +name: 'Install Anchor with cached modules' +description: 'Run cargo install anchor-cli with cached modules' + +runs: + using: 'composite' + steps: + - name: Cache cargo registry + uses: actions/cache@v4 + with: + path: ~/.cargo/registry + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo-registry- + + - name: Cache cargo index + uses: actions/cache@v4 + with: + path: ~/.cargo/git + key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo-git- + + - name: Cache cargo build + uses: actions/cache@v4 + with: + path: target + key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo-build-target- + + - name: Anchor Install + uses: metadaoproject/install-anchor@v2 + with: + anchor-version: '0.29.0' + solana-cli-version: '1.17.15' + node-version: '20.10.0' diff --git a/.github/actions/install/action.yml b/.github/actions/npm-install/action.yml similarity index 74% rename from .github/actions/install/action.yml rename to .github/actions/npm-install/action.yml index ff84082..473a5cb 100644 --- a/.github/actions/install/action.yml +++ b/.github/actions/npm-install/action.yml @@ -4,16 +4,18 @@ description: 'Run pnpm install with cached modules' runs: using: 'composite' steps: - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: lts/* - - name: Install pnpm - uses: pnpm/action-setup@v2 - id: pnpm-install + - run: corepack enable + shell: bash + + - uses: actions/setup-node@v4 with: - run_install: false + node-version: 20 + cache: "pnpm" + + - name: Install dependencies + run: pnpm install + shell: bash - name: Get pnpm store directory id: pnpm-cache diff --git a/.github/actions/publish/action.yml b/.github/actions/publish/action.yml new file mode 100644 index 0000000..e304c92 --- /dev/null +++ b/.github/actions/publish/action.yml @@ -0,0 +1,26 @@ +name: 'Publish' +description: 'Publish the project' +inputs: + npm_token: + description: 'NPM token' + required: true + +runs: + using: 'composite' + steps: + - name: Install Dependencies + run: cd sdk && pnpm install + shell: bash + - name: Build SDK + run: pnpm run build:sdk + shell: bash + - name: Setup .npmrc + run: echo "//registry.npmjs.org/:_authToken=${{ inputs.npm_token }}" > sdk/.npmrc + shell: bash + - name: Publish SDK + run: | + cd sdk && pnpm publish --access public --no-git-checks \ + ${{ contains(github.ref_name, 'alpha') && '--tag alpha' || contains(github.ref_name, 'beta') && '--tag beta' || '' }} + shell: bash + env: + NODE_AUTH_TOKEN: ${{ inputs.npm_token }} \ No newline at end of file diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 8a23675..d9433c4 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -5,17 +5,12 @@ on: branches: ['main'] jobs: - build: + build-and-test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: 'Solana Anchor build' - uses: metadaoproject/setup-anchor@v2 - with: - anchor-version: '0.29.0' - solana-cli-version: '1.17.15' - node-version: '20.10.0' - - uses: ./.github/actions/install + - uses: ./.github/actions/anchor-install + - uses: ./.github/actions/npm-install - run: anchor build - - run: anchor run build_sdk - - run: pnpm run test + - run: pnpm run build:sdk + - run: pnpm run test \ No newline at end of file diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 546f472..2184375 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -13,8 +13,7 @@ jobs: permissions: contents: write steps: - - name: Checkout code - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - uses: ncipollo/release-action@v1 with: draft: false @@ -24,23 +23,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: ./.github/actions/install - - name: 'Solana Anchor build' - uses: metadaoproject/setup-anchor@v2 + - uses: ./.github/actions/anchor-install + - uses: ./.github/actions/npm-install + - uses: ./.github/actions/publish with: - anchor-version: '0.29.0' - solana-cli-version: '1.17.15' - node-version: '20.10.0' - - uses: ./.github/actions/install - - run: anchor build - - run: anchor run build_sdk - - name: Install Dependencies - run: cd sdk && pnpm install - - name: Build SDK - run: pnpm run build:sdk - - name: Publish SDK - run: | - pnpm publish --access public \ - ${{ contains(github.ref_name, 'alpha') && '--tag alpha' || contains(github.ref_name, 'beta') && '--tag beta' || '' }} - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + npm_token: ${{ secrets.NPM_TOKEN }} \ No newline at end of file