Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: publish npm workflow #21

Merged
merged 5 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Publish to NPM

on:
release:
types: [published]

jobs:
publish:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v3
fadeev marked this conversation as resolved.
Show resolved Hide resolved

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "21"
registry-url: "https://registry.npmjs.org"

- name: Install Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

      - name: Install stable
        uses: dtolnay/rust-toolchain@stable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


- name: Install Solana CLI
run: |
sh -c "$(curl -sSfL https://release.solana.com/v1.18.15/install)"
export PATH="/home/runner/.local/share/solana/install/active_release/bin:$PATH"
solana --version

- name: Install Anchor CLI
run: |
cargo install --git https://github.com/coral-xyz/anchor --tag v0.30.0 anchor-cli --locked
anchor --version
fbac marked this conversation as resolved.
Show resolved Hide resolved

- name: Build
run: anchor build

- name: Prepare IDL Files
run: |
mv target/idl ./
fbac marked this conversation as resolved.
Show resolved Hide resolved

- name: Determine NPM Tag
id: determine-npm-tag
run: |
VERSION_TAG=${GITHUB_REF#refs/tags/v}
if [[ $VERSION_TAG == *"-"* ]]; then
echo ::set-output name=NPM_TAG::${VERSION_TAG#*-}
else
echo ::set-output name=NPM_TAG::latest
fi
env:
GITHUB_REF: ${{ github.ref }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is deprecated by GitHub, please consider using:

steps:
  - name: Set the foo value
    id: foo_value
    run: |
      echo "foo=bar" >> "$GITHUB_ENV"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, but this has never worked for me. I propose we improve this in a follow-up PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a working example in a workflow on this repository:

        - name: Record Rust version
          run: echo "RUST=$(rustc --version)" >> "$GITHUB_ENV"
        - name: Upload to codecov.io
          uses: codecov/codecov-action@v4
          with:
            fail_ci_if_error: true
            token: ${{ secrets.CODECOV_TOKEN }}
            env_vars: OS,RUST

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


- name: Publish to NPM
run: |
yarn publish --access public --new-version ${GITHUB_REF#refs/tags/v} --tag ${{
steps.determine-npm-tag.outputs.NPM_TAG }} --no-git-tag-version
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_REF: ${{ github.ref }}
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"name": "@zetachain/protocol-contracts-solana",
"private": false,
"version": "0.0.0-set-on-publish",
"description": "Package contains IDL files for the Solana Gateway program, enabling cross-chain functionality with ZetaChain",
"files": [
"idl"
],
"scripts": {
"lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
"lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
Expand All @@ -21,4 +28,4 @@
"ts-mocha": "^10.0.0",
"typescript": "^4.3.5"
}
}
}
Loading