From: Evert Timberg Date: Tue, 13 Oct 2020 21:12:19 +0000 (-0400) Subject: Remove release branch workflow (#7827) X-Git-Tag: v3.0.0-beta.4~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ff354cc5b8245049887f24cf855d19d928d6d8de;p=thirdparty%2FChart.js.git Remove release branch workflow (#7827) * GitHub actions uses locked install for CI * Add initial GitHub action to publish to NPM * Detect the NPM tag (latest vs next) depending on the git tag * Deploy docs from releases & master commits * Remove Travis CI * Update repo badge to use actions status * Remove Travis env vars and update docs-config to take a parameter * Update publish script regex to match other scripts * Deploy docs action only runs in one spot --- diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 15a6d79c7..b366dba83 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,7 +41,7 @@ jobs: shell: bash - name: Build and Test run: | - npm install + npm ci npm run build npm test - name: Package diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml new file mode 100644 index 000000000..e6c7e2f3d --- /dev/null +++ b/.github/workflows/deploy-docs.yml @@ -0,0 +1,28 @@ +# This workflow publishes new documentation to https://chartjs.org/docs/master after every commit +name: CI + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js + uses: actions/setup-node@v1 + - name: Package & Deploy Docs + run: | + npm ci + npm run build + ./scripts/docs-config.sh "master" + npm run docs + npm run typedoc + npm pack + ./scripts/deploy-docs.sh "master" + env: + GITHUB_TOKEN: ${{ secrets.GH_AUTH_TOKEN }} + GH_AUTH_EMAIL: ${{ secrets.GH_AUTH_EMAIL }} diff --git a/.github/workflows/npmpublish.yml b/.github/workflows/npmpublish.yml new file mode 100644 index 000000000..8565c0475 --- /dev/null +++ b/.github/workflows/npmpublish.yml @@ -0,0 +1,75 @@ +# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created +# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages + +name: Node.js Package + +on: + release: + types: [published] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Use Node.js + uses: actions/setup-node@v1 + - name: Setup xvfb + run: | + Xvfb :99 -screen 0 1024x768x24 & + echo "::set-env name=DISPLAY:::99.0" + - name: Test + run: | + npm ci + npm test + + publish-npm: + needs: test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: 12 + registry-url: https://registry.npmjs.org/ + # Since we created the release in the UI, we need to find it. + # This step gets the release from the GITHUB_REF env var + - name: Get release + id: get_release + uses: bruceadams/get-release@v1.2.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Setup and build + run: | + npm ci + npm install -g json + json -I -f package.json -e "this.version=\"$GITHUB_REF\"" + json -I -f package-lock.json -e "this.version=\"$GITHUB_REF\"" + npm run build + ./scripts/docs-config.sh "${GITHUB_REF:1}" + npm run docs + npm run typedoc + npm pack + - name: Publish to NPM + run: ./scripts/publish.sh + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + # On releases, GITHUB_REF is the tag name which is the version + # However, it will include the leading "v", so we need to strip that + # first character off here since we want the docs folder to not have + # the "v" in it. + - name: Deploy Docs + run: ./scripts/deploy-docs.sh "${GITHUB_REF:1}" + env: + GITHUB_TOKEN: ${{ secrets.GH_AUTH_TOKEN }} + GH_AUTH_EMAIL: ${{ secrets.GH_AUTH_EMAIL }} + - name: Upload NPM package file + id: upload-npm-package-file + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.get_release.outputs.upload_url }} + asset_path: chart.js-$GITHUB_REF.tgz + asset_name: chart.js-$GITHUB_REF.tgz + asset_content_type: application/gzip diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 4983aefc7..000000000 --- a/.travis.yml +++ /dev/null @@ -1,59 +0,0 @@ -language: node_js -node_js: - - lts/* - -before_install: - - "export CHROME_BIN=/usr/bin/google-chrome" - -services: - - xvfb - -script: - - npm run build - - npm test - - ./scripts/docs-config.sh - - npm run docs - - npm run typedoc - - npm pack - - cat ./coverage/lcov.info | ./node_modules/.bin/coveralls || true - -sudo: required -dist: bionic - -addons: - chrome: stable - firefox: latest - -# IMPORTANT: scripts require GITHUB_AUTH_TOKEN and GITHUB_AUTH_EMAIL environment variables -# IMPORTANT: scripts has to be set executables in the Git repository (error 127) -# https://github.com/travis-ci/travis-ci/issues/5538#issuecomment-225025939 - -deploy: -- provider: script - script: ./scripts/deploy.sh - skip_cleanup: true - on: - all_branches: true -- provider: script - script: ./scripts/release.sh - skip_cleanup: true - on: - all_branches: true - condition: $TRAVIS_BRANCH =~ ^(release.*)$ -- provider: releases - api_key: $GITHUB_AUTH_TOKEN - skip_cleanup: true - file_glob: true - file: - - ./dist/*.css - - ./dist/*.js - - ./dist/*.zip - on: - tags: true -- provider: npm - email: $NPM_AUTH_EMAIL - api_key: $NPM_AUTH_TOKEN - skip_cleanup: true - on: - tags: true - tag: next diff --git a/README.md b/README.md index b75d1b66a..33e7b811c 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@

Downloads - Builds + GitHub Workflow Status Coverage Awesome Slack diff --git a/scripts/deploy.sh b/scripts/deploy-docs.sh old mode 100755 new mode 100644 similarity index 65% rename from scripts/deploy.sh rename to scripts/deploy-docs.sh index 497ba65cc..128cda6a1 --- a/scripts/deploy.sh +++ b/scripts/deploy-docs.sh @@ -4,20 +4,9 @@ set -e TARGET_DIR='gh-pages' TARGET_BRANCH='master' -TARGET_REPO_URL="https://$GITHUB_AUTH_TOKEN@github.com/chartjs/chartjs.github.io.git" +TARGET_REPO_URL="https://$GITHUB_TOKEN@github.com/chartjs/chartjs.github.io.git" -# Note: this code also exists in docs-config.sh -# Make sure that this script is executed only for the release and master branches -VERSION_REGEX='[[:digit:]]+.[[:digit:]]+.[[:digit:]]+(-.*)?' -if [[ "$TRAVIS_BRANCH" =~ ^release.*$ ]]; then - # Travis executes this script from the repository root, so at the same level than package.json - VERSION=$(node -p -e "require('./package.json').version") -elif [ "$TRAVIS_BRANCH" == "master" ]; then - VERSION="master" -else - echo "Skipping deploy because this is not the master or release branch" - exit 0 -fi +VERSION=$1 function move_sample_scripts { local subdirectory=$1 @@ -47,7 +36,7 @@ function update_tagged_files { if [ "$VERSION" == "master" ]; then update_with_tag master elif [[ "$VERSION" =~ ^[^-]+$ ]]; then - update_with_tag lastest + update_with_tag latest else update_with_tag next fi @@ -75,9 +64,9 @@ update_tagged_files git add --all git remote add auth-origin $TARGET_REPO_URL -git config --global user.email "$GITHUB_AUTH_EMAIL" +git config --global user.email "$GH_AUTH_EMAIL" git config --global user.name "Chart.js" -git commit -m "Deploy $VERSION from $TRAVIS_REPO_SLUG" -m "Commit: $TRAVIS_COMMIT" +git commit -m "Deploy $VERSION from $GITHUB_REPOSITORY" -m "Commit: $GITHUB_SHA" git push -q auth-origin $TARGET_BRANCH git remote rm auth-origin diff --git a/scripts/docs-config.sh b/scripts/docs-config.sh index ed557f357..dd0e39610 100755 --- a/scripts/docs-config.sh +++ b/scripts/docs-config.sh @@ -2,18 +2,7 @@ set -e -# Note: this code also exists in deploy.sh -# Make sure that this script is executed only for the release and master branches -VERSION_REGEX='[[:digit:]]+.[[:digit:]]+.[[:digit:]]+(-.*)?' -if [[ "$TRAVIS_BRANCH" =~ ^release.*$ ]]; then - # Travis executes this script from the repository root, so at the same level than package.json - VERSION=$(node -p -e "require('./package.json').version") -elif [ "$TRAVIS_BRANCH" == "master" ]; then - VERSION="master" -else - echo "Skipping docs configuration because this is not the master or release branch" - exit 0 -fi +VERSION=$1 # Note: this code also exists in deploy.sh # tag is next|latest|master @@ -23,7 +12,7 @@ function update_config { if [ "$VERSION" == "master" ]; then tag=master elif [[ "$VERSION" =~ ^[^-]+$ ]]; then - tag=lastest + tag=latest else tag=next fi diff --git a/scripts/publish.sh b/scripts/publish.sh new file mode 100644 index 000000000..c10cb7194 --- /dev/null +++ b/scripts/publish.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +NPM_TAG="next" + +if [[ "$GITHUB_REF" =~ ^[^-]+$ ]]; then + echo "Release tag indicates a full release. Releasing as \"latest\"." + NPM_TAG="latest" +fi + +npm publish --tag "$NPM_TAG" diff --git a/scripts/release.sh b/scripts/release.sh deleted file mode 100755 index 53afebc85..000000000 --- a/scripts/release.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -set -e - -if [[ ! "$TRAVIS_BRANCH" =~ ^release.*$ ]]; then - echo "Skipping release because this is not the 'release' branch" - exit 0 -fi - -# Travis executes this script from the repository root, so at the same level than package.json -VERSION=$(node -p -e "require('./package.json').version") - -# Make sure that the associated tag doesn't already exist -GITTAG=$(git ls-remote origin refs/tags/v$VERSION) -if [ "$GITTAG" != "" ]; then - echo "Tag for package.json version already exists, aborting release" - exit 1 -fi - -git remote add auth-origin https://$GITHUB_AUTH_TOKEN@github.com/$TRAVIS_REPO_SLUG.git -git config --global user.email "$GITHUB_AUTH_EMAIL" -git config --global user.name "Chart.js" -git checkout --detach --quiet -git add -f dist/*.js -git commit -m "Release $VERSION" -git tag -a "v$VERSION" -m "Version $VERSION" -git push -q auth-origin refs/tags/v$VERSION 2>/dev/null -git remote rm auth-origin -git checkout -f @{-1}