From 8a92fe202660e63834dda74cfa1bcbafd8a31b55 Mon Sep 17 00:00:00 2001 From: Anze Skerlavaj Date: Mon, 27 Jan 2020 15:27:19 +0100 Subject: [PATCH 1/3] Add GitHub Actions --- .github/workflows/on_push.yaml | 18 +++++++++++++ .github/workflows/on_release.yaml | 44 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 .github/workflows/on_push.yaml create mode 100644 .github/workflows/on_release.yaml diff --git a/.github/workflows/on_push.yaml b/.github/workflows/on_push.yaml new file mode 100644 index 00000000..cf1671e0 --- /dev/null +++ b/.github/workflows/on_push.yaml @@ -0,0 +1,18 @@ +name: Lint +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + + - name: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: '12' + + - name: Run linter + run: | + npm install + npm run lint diff --git a/.github/workflows/on_release.yaml b/.github/workflows/on_release.yaml new file mode 100644 index 00000000..89e2ccb3 --- /dev/null +++ b/.github/workflows/on_release.yaml @@ -0,0 +1,44 @@ +name: Deploy to NPM +on: + release: + types: [published] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + + - name: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: '12' + + - name: Install packages + if: success() && startsWith(github.ref, 'refs/tags/v') + run: | + npm install + + - name: Build and deploy + if: success() && startsWith(github.ref, 'refs/tags/v') + env: + GITHUB_REF_TAG: ${{ github.ref }} + NPMJS_REGISTRY: registry.npmjs.org + NPMJS_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + export VERSION=${GITHUB_REF_TAG:10:50} + echo "Version is $VERSION" + npm version --no-git-tag-version "${VERSION}" + npm run build + echo "//${NPMJS_REGISTRY}/:_authToken=${NPMJS_TOKEN}" > .npmrc + [ $(echo "${VERSION}" | grep rc) ] && echo "publishing with next tag to npm - ${VERSION}" || echo "publishing with latest tag to npm - ${VERSION}" + [ $(echo "${VERSION}" | grep rc) ] && npm publish --access public --tag next || npm publish --access public + echo "Published to npm registry: ${NPMJS_REGISTRY}" + tar -cvzf /tmp/dist.tar.gz dist/ + + - name: Create artifacts + if: success() && startsWith(github.ref, 'refs/tags/v') + uses: actions/upload-artifact@master + with: + name: dist.tar.gz + path: /tmp/dist.tar.gz From a7924aaa3be37c28bf70b1ce615e93e7dfe91aea Mon Sep 17 00:00:00 2001 From: Anze Skerlavaj Date: Mon, 27 Jan 2020 15:56:29 +0100 Subject: [PATCH 2/3] Remove GitLab CI --- .gitlab-ci.yml | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 4215f8f0..00000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,35 +0,0 @@ -image: node:8-alpine - -stages: - - test - - deploy - -### TEST: ### -install_packages_and_run_lint: - stage: test - script: - - npm install - - npm run lint - artifacts: - expire_in: 2 days - paths: - # we will need the installed packages in next step, so cache might not be enough - we need to create an artifact: - - ./node_modules - -publish_to_npm: - stage: deploy - when: manual - variables: - NPMJS_REGISTRY: registry.npmjs.org - only: - variables: - # We only allow this job to run if there was a tag, starting with - # "vX.Y.Z". The reason is that we put the version in package.json. - - $CI_COMMIT_TAG =~ /^v[0-9]+[.][0-9]+[.][0-9]+([-]rc[.][a-z0-9_-]+)?$/ - script: - - npm version --no-git-tag-version "${CI_COMMIT_TAG}" - - npm run build - - echo "//${NPMJS_REGISTRY}/:_authToken=${NPMJS_TOKEN}" > .npmrc - - '[ $(echo "${CI_COMMIT_TAG}" | grep rc) ] && echo "publishing with next tag to npm ${CI_COMMIT_TAG}" || echo "publishing with latest tag to npm"' - - '[ $(echo "${CI_COMMIT_TAG}" | grep rc) ] && npm publish --access public --tag next || npm publish --access public' - - 'echo "Published to npm registry: ${NPM_REGISTRY}"' From 2e9761b037197ca4103f6f9fe4736391b398de9f Mon Sep 17 00:00:00 2001 From: Anze Skerlavaj Date: Tue, 28 Jan 2020 12:51:15 +0100 Subject: [PATCH 3/3] Make version extraction from ref tag more explicit --- .github/workflows/on_release.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/on_release.yaml b/.github/workflows/on_release.yaml index 89e2ccb3..6c3bad23 100644 --- a/.github/workflows/on_release.yaml +++ b/.github/workflows/on_release.yaml @@ -26,7 +26,8 @@ jobs: NPMJS_REGISTRY: registry.npmjs.org NPMJS_TOKEN: ${{ secrets.NPM_TOKEN }} run: | - export VERSION=${GITHUB_REF_TAG:10:50} + echo "Extracting version from GITHUB_REF_TAG: $GITHUB_REF_TAG" + export VERSION=$(echo "$GITHUB_REF_TAG" | sed -e "s#^refs/tags/##") echo "Version is $VERSION" npm version --no-git-tag-version "${VERSION}" npm run build