Skip to content
Draft
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
77 changes: 67 additions & 10 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
name: Node.js Package

on:
push:
branches:
- "RD-637_gh-action-cdn-release"
release:
types: [created]

env:
CDN_REPO: "maptiler/cdn.maptiler.com"
CDN_REPO_BRANCH: "maptiler-ar-control-test"

jobs:
build-and-publish:
runs-on: ubuntu-latest
Expand All @@ -17,19 +24,69 @@ jobs:
with:
node-version: 20
registry-url: https://registry.npmjs.org/

- run: npm ci

- run: npm run make

- name: Extract repository name
run: |
REPO_NAME=${GITHUB_REPOSITORY##*/}
echo "REPO_NAME=$REPO_NAME" >> $GITHUB_ENV

- name: Extract package version
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV

- name: Publish NPM package (regular)
if: "!github.event.release.prerelease"
# - name: Publish NPM package (regular)
# if: "!github.event.release.prerelease"
# run: |
# npm publish
# env:
# NODE_AUTH_TOKEN: ${{secrets.npm_token}}

# - name: Publish NPM package (pre-release)
# if: "github.event.release.prerelease"
# run: |
# npm publish --tag next
# env:
# NODE_AUTH_TOKEN: ${{secrets.npm_token}}

- name: Check if target directory exists and abort if it does
run: |
npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
if [ -d "cdn/${REPO_NAME}/${PACKAGE_VERSION}" ]; then
echo "Directory cdn/${REPO_NAME}/${PACKAGE_VERSION} already exists. Aborting."
exit 1
fi

- name: Checkout CDN repo
uses: actions/checkout@v4
with:
repository: ${{ env.CDN_REPO }}
path: cdn
# key here

- name: Publish NPM package (pre-release)
if: "github.event.release.prerelease"
- name: Push to CDN
run: |
npm publish --tag next
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
echo "Repository name: $REPO_NAME"
echo "Package version is $PACKAGE_VERSION"

# mkdir -p cdn/${REPO_NAME}/${PACKAGE_VERSION}
# cp -r build/* cdn/${REPO_NAME}/${PACKAGE_VERSION}
# cd cdn
# git config user.name "github-actions"
# git config user.email "github-actions@github.com"
# git checkout -b "${CDN_REPO_BRANCH}" || git checkout "${CDN_REPO_BRANCH}"
# git add .
# git commit -m "Add ${REPO_NAME} ${PACKAGE_VERSION}"
# git push origin "${CDN_REPO_BRANCH}"
# ... pull-request here ...
# verify if this stuff bellow works
# echo "${{ secrets.ACCESS_TOKEN }}" > token.txt
# gh auth login --with-token < token.txt
# gh pr create \
# --body "" \
# --title "chore: update scripts to $LATEST_TAG" \
# --head "$BRANCH_NAME" \
# --base "main"