From 877fb62064cb019e7d74910bd05bb406dbc263f5 Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Tue, 25 Feb 2025 09:57:56 +1100 Subject: [PATCH] feat: add Gitea Actions workflow for publishing to npm --- .gitea/workflows.publishToNpm.yaml | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .gitea/workflows.publishToNpm.yaml diff --git a/.gitea/workflows.publishToNpm.yaml b/.gitea/workflows.publishToNpm.yaml new file mode 100644 index 0000000..08c381e --- /dev/null +++ b/.gitea/workflows.publishToNpm.yaml @@ -0,0 +1,46 @@ +name: Publish to npm + +on: + push: + branches: + - main + - dev + +jobs: + publish: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '22' + registry-url: 'https://registry.npmjs.org/' + + - name: Install dependencies + run: npm install + + - name: Determine package name + id: package_name + run: | + if [ "${{ gitea.ref }}" == "refs/heads/main" ]; then + echo "PACKAGE_NAME=datenel-react" >> $GITEA_ENV + echo "ACCESS_LEVEL=public" >> $GITEA_ENV + elif [ "${{ gitea.ref }}" == "refs/heads/dev" ]; then + echo "PACKAGE_NAME=@astrian/datenel-vue3-dev" >> $GITEA_ENV + echo "ACCESS_LEVEL=restricted" >> $GITEA_ENV + fi + + - name: Update package.json for dev releases + if: GITEA.ref == 'refs/heads/dev' + run: | + jq --arg name "@astrian/datenel-vue3-dev" '.name=$name' package.json > temp.json && mv temp.json package.json + jq --arg version "0.0.0-dev.$(date +%s)" '.version=$version' package.json > temp.json && mv temp.json package.json + + - name: Publish to npm + run: npm publish --access $ACCESS_LEVEL + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}