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

fix: updated ci workflow #14

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Changes from all commits
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
83 changes: 44 additions & 39 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,58 @@
name: CI Workflow
name: Publish library on NPM

on:
release:
types: [published]
push:
branches:
- main
- fix/ci-errors


jobs:
build:
publish:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Use Node.js

- name: "Check file existence"
id: check_files
uses: andstor/file-existence-action@v3
with:
files: "package.json, README.md"

# - name: File exists
# # Only runs if all of the files exists
# run: exit 1

# - name: Get package.json package name and match with repository name
# run: |
# echo PACKAGE_NAME=$(cat package.json | jq .name | cut -f2 -d"\"" | cut -f2 -d"@") >> $GITHUB_OUTPUT
# echo PACKAGE_VERSION="refs/tags/v"$(cat package.json | jq .version | cut -f2 -d"\"") >> $GITHUB_OUTPUT
# echo PACKAGE_REPOSITORY=$(cat package.json | jq .repository | cut -f2 -d"\"" | sed 's/:/\//' | sed 's/@/:\/\//') >> $GITHUB_OUTPUT
# id: get_package_info

# - name: Check if package_name matches with repository name
# if: github.repository != steps.get_package_info.outputs.PACKAGE_NAME
# # Fail if package name not properly configured
# run: exit 1

# - name: Check if package version matches with tag
# if: github.ref != steps.get_package_info.outputs.PACKAGE_VERSION
# # Fail if package version not properly setted
# run: exit 1

# - name: Check if package repository matches with repository
# # Fail if package repository doesn't match with repository
# run: exit 1

- name: Push package to npmjs.com
uses: actions/setup-node@v4
with:
node-version: '20.x'
node-version: 20
registry-url: https://registry.npmjs.org/

- name: Install pnpm
run: npm install -g pnpm
Expand All @@ -29,52 +63,23 @@ jobs:
- name: Build project
run: pnpm build

- name: Verify dist folder exists
run: |
if [ ! -d "dist" ]; then
echo "Error: dist folder not found!"
exit 1
fi

publish:
runs-on: ubuntu-latest
needs: build

steps:
- name: Checkout
uses: actions/checkout@v4
run: |
echo PACKAGE_NAME=$(cat package.json | jq .name | cut -f2 -d"\"" | cut -f2 -d"@") >> $GITHUB_OUTPUT
echo PACKAGE_VERSION="refs/tags/v"$(cat package.json | jq .version | cut -f2 -d"\"") >> $GITHUB_OUTPUT
echo PACKAGE_REPOSITORY=$(cat package.json | jq .repository | cut -f2 -d"\"" | sed 's/:/\//' | sed 's/@/:\/\//') >> $GITHUB_OUTPUT
id: get_package_info

- name: Set up Node.js for npm publishing
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/

- name: Install dependencies
run: npm ci

- name: Pre-upload validation
- name: Pre upload validation
id: pack
run: |
run: |
npm pack --dry-run >> output 2>&1
echo PRE_UPLOAD_HASH=$(cat output | grep shasum | cut -f4 -d" ") >> $GITHUB_OUTPUT

- name: Publish package
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Post-upload validation
id: unpack
run: |
PACKAGE_NAME=$(cat package.json | jq .name | cut -f2 -d"\"")@$(cat package.json | jq .version | cut -f2 -d"\"")
echo POST_UPLOAD_HASH=$(npm view $PACKAGE_NAME | grep shasum | cut -f4 -d" ") >> $GITHUB_OUTPUT

- name: Pre and post upload validation
- name: Pre and Post Upload validation
if: steps.pack.outputs.PRE_UPLOAD_HASH != steps.unpack.outputs.POST_UPLOAD_HASH
run: exit 1
Loading