diff --git a/.changeset/config.json b/.changeset/config.json index c9c7d3d7d..653104a1e 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -1,6 +1,6 @@ { "$schema": "https://unpkg.com/@changesets/config@1.6.0/schema.json", - "changelog": "@changesets/cli/changelog", + "changelog": "@changesets/changelog-github", "commit": false, "linked": [["astro", "@astrojs/parser"]], "access": "public", diff --git a/.eslintignore b/.eslintignore index d6505ca83..c2d3e8400 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,4 +3,6 @@ !packages/astro/**/*.js !packages/astro/**/*.ts packages/astro/test/**/*.js -packages/astro/vendor/vite/**/* \ No newline at end of file +packages/astro/vendor/vite/**/* +.github +.changeset diff --git a/.github/extract-artifacts.sh b/.github/extract-artifacts.sh new file mode 100755 index 000000000..03f0d19a1 --- /dev/null +++ b/.github/extract-artifacts.sh @@ -0,0 +1,11 @@ +cd artifacts +mkdir -p ../tmp/packages +mv * ../tmp/packages +cd ../tmp +tar -cvzpf artifacts.tar.gz * +mv artifacts.tar.gz ../artifacts.tar.gz +cd .. +tar -xvzpf artifacts.tar.gz +rm -rf artifacts +rm -rf tmp +rm -f artifacts.tar.gz diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 45a632776..6028ed774 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,8 +11,98 @@ on: - 'examples/**' - 'www/**' +permissions: + checks: write + contents: read + +# Automatically cancel in-progress actions on the same branch +concurrency: + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }} + cancel-in-progress: true + +defaults: + run: + shell: bash + jobs: + # Lint can run in parallel with Build. + # We also run `yarn install` with the `--prefer-offline` flag to speed things up. + lint: + name: Lint + # Lint cannot run on forks, so just skip those! See https://github.com/wearerequired/lint-action/issues/13 + if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.owner.login == github.repository_owner }} + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v2 + + - name: Setup Node + uses: actions/setup-node@v2 + with: + node-version: 16 + cache: 'yarn' + + - name: Install NPM Dependencies + run: yarn install --prefer-offline --frozen-lockfile --ignore-engines + env: + CI: true + + - name: Status + run: git status + + - name: Lint + uses: wearerequired/lint-action@v1.10.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + eslint: true + eslint_args: --ignore-pattern test --ignore-pattern vendor + eslint_dir: packages/astro + eslint_extensions: ts + prettier: true + auto_fix: true + git_name: GitHub Action + git_email: github-action@users.noreply.github.com + commit_message: '[ci] ${linter} fix' + github_token: ${{ secrets.GITHUB_TOKEN }} + neutral_check_on_warning: true + + # Build installs all devDependencies and runs our full build pipeline. + # We upload all `dist/` artifacts to GitHub, which can be shared by all dependent jobs. build: + name: Build Packages + if: "!contains(github.event.head_commit.message, '[skip-ci]')" + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup Node + uses: actions/setup-node@v2 + with: + node-version: 16 + cache: 'yarn' + + - name: Install NPM Dependencies + run: yarn install --frozen-lockfile --ignore-engines --registry https://registry.npmjs.org --network-timeout 300000 + env: + CI: true + + - name: Build Packages + run: yarn build:all + + - name: Upload Package Artifacts + uses: actions/upload-artifact@v2 + with: + name: artifacts + path: packages/**/dist/* + if-no-files-found: error + + # Test depends on Build's output, which allows us to skip any build process! + # We also run `yarn install` with the `--prefer-offline` flag to speed things up. + test: + name: 'Test: ${{ matrix.os }} (node@${{ matrix.node_version }})' + if: "!contains(github.event.head_commit.message, '[skip-ci]')" runs-on: ${{ matrix.os }} strategy: matrix: @@ -24,86 +114,114 @@ jobs: - os: macos-latest node_version: 16 fail-fast: false - env: - LANG: en-us - name: 'Test: node-${{ matrix.node_version }}, ${{ matrix.os }}' + needs: + - build steps: - - name: Check out code using Git + - name: Checkout uses: actions/checkout@v2 - - name: Set Node version to ${{ matrix.node_version }} + - name: Setup node@${{ matrix.node_version }} uses: actions/setup-node@v2 with: node-version: ${{ matrix.node_version }} cache: 'yarn' - - name: Debug - run: yarn versions + - name: Download Build Artifacts + uses: actions/download-artifact@v2 - - name: Install dependencies - run: yarn install --frozen-lockfile --ignore-engines + - name: Extract Artifacts + run: ./.github/extract-artifacts.sh - - name: Build Astro - run: yarn build:all + - name: Install NPM Dependencies + run: yarn install --prefer-offline --frozen-lockfile --ignore-engines + env: + CI: true - name: Test run: yarn test - lint: + smoke: + name: 'Smoke Test: ${{ matrix.target }}' runs-on: ubuntu-latest - name: 'Lint: node-16, ubuntu-latest' + if: "!contains(github.event.head_commit.message, '[skip-ci]')" + strategy: + matrix: + target: [docs, www] + needs: + - build steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 + - name: Checkout + uses: actions/checkout@v2 - - name: Set Node version to 16 + - name: Setup Node uses: actions/setup-node@v2 with: node-version: 16 cache: 'yarn' - - name: Debug - run: yarn versions + - name: Download Build Artifacts + uses: actions/download-artifact@v2 - - name: Install dependencies - run: yarn install --frozen-lockfile --ignore-engines + - name: Extract Artifacts + run: ./.github/extract-artifacts.sh + + - name: Install NPM Dependencies + run: yarn install --frozen-lockfile --ignore-engines --registry https://registry.npmjs.org --network-timeout 300000 + env: + CI: true - name: Build - run: yarn build:all + run: yarn build + working-directory: ${{ matrix.target }} - - name: Lint - run: yarn lint + # Changelog can only run _after_ Build and Test. + # We download all `dist/` artifacts from GitHub to skip the build process. + changelog: + name: Changelog PR or Release + if: ${{ !contains(github.event.head_commit.message, '[skip-ci]') && github.ref_name == 'main' && github.repository_owner == 'withastro' }} + needs: [lint, test, smoke] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 - # NOTE: temporarily disabled until `next` branch can build docs again - # smoke: - # runs-on: ubuntu-latest - # name: 'Smoke: node-14, ubuntu-latest' - # steps: - # - name: Check out code using Git - # uses: actions/checkout@v2 - # with: - # fetch-depth: 0 + - name: Setup Node + uses: actions/setup-node@v2 + with: + node-version: 16 + cache: 'yarn' + + - name: Download Build Artifacts + uses: actions/download-artifact@v2 - # - name: Set Node version to 16 - # uses: actions/setup-node@v2 - # with: - # node-version: 16 - # cache: 'yarn' + - name: Extract Artifacts + run: ./.github/extract-artifacts.sh - # - name: Debug - # run: yarn versions + - name: Install NPM Dependencies + run: yarn install --prefer-offline --frozen-lockfile --ignore-engines + env: + CI: true + + - name: Create Release Pull Request or Publish + id: changesets + uses: changesets/action@master + with: + publish: changeset publish + commit: '[ci] release' + title: '[ci] release' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - # - name: Install dependencies - # run: yarn install --frozen-lockfile --ignore-engines + - name: Generate Notification + id: notification + if: steps.changesets.outputs.published == 'true' + run: message=$(node scripts/notify/index.js '${{ steps.changesets.outputs.publishedPackages }}') && echo ::set-output name=message::${message//$'\n'/'%0A'} - # - name: Build - # run: yarn build:all - - # - name: "Smoke Test: Build 'docs'" - # run: yarn build - # working-directory: ./docs - - # - name: "Smoke Test: Build 'www'" - # run: yarn build - # working-directory: ./www + - name: Discord Notification + if: steps.changesets.outputs.published == 'true' + id: discord-notification + env: + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} + uses: Ilshidur/action-discord@0.3.2 + with: + args: ${{ steps.notification.outputs.message }} diff --git a/.github/workflows/congratsbot.yml b/.github/workflows/congratsbot.yml deleted file mode 100644 index d9552ffe2..000000000 --- a/.github/workflows/congratsbot.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: "Discord:congratsbot" - -on: - push: - branches: - - main - -jobs: - congrats: - name: "discord:congratsbot" - if: github.repository == 'withastro/astro' - runs-on: ubuntu-latest - steps: - - id: setup - run: | - TRIMMED=$(echo "${{ github.event.commits[0].message }}" | sed '1!d;q') - echo "::set-output name=COMMIT_MSG::${TRIMMED}" - - name: Send a Discord notification when a PR is merged - env: - DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_CONGRATS }} - # DISCORD_AVATAR: ${{ github.event.pull_request.user.avatar_url }} - uses: Ilshidur/action-discord@0.3.2 - with: - args: '**Sweet!** <${{ github.event.commits[0].author.name }}> just merged ["\"${{ steps.setup.outputs.COMMIT_MSG }}\""]() ```${{ github.event.commits[0].message }}```' diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml index 6a29b424e..e6eb47cf0 100644 --- a/.github/workflows/label.yml +++ b/.github/workflows/label.yml @@ -8,6 +8,7 @@ on: jobs: triage: runs-on: ubuntu-latest + if: github.repository_owner == 'withastro' steps: - uses: actions/labeler@v3 with: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..350be30e9 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,83 @@ +name: Main Checks + +on: + push: + branches: + - main + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +# Automatically cancel in-progress actions on the same branch +concurrency: + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + congrats: + name: congratsbot + if: ${{ github.repository_owner == 'withastro' && !contains(github.event.head_commit.message, '[skip-ci]') }} + runs-on: ubuntu-latest + steps: + - id: setup + run: | + TRIMMED=$(echo "${{ github.event.commits[0].message }}" | sed '1!d;q') + echo "::set-output name=COMMIT_MSG::${TRIMMED}" + - name: Send a Discord notification when a PR is merged + env: + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK_CONGRATS }} + # DISCORD_AVATAR: ${{ github.event.pull_request.user.avatar_url }} + uses: Ilshidur/action-discord@0.3.2 + with: + args: '**Sweet!** <${{ github.event.commits[0].author.name }}> just merged ["\"${{ steps.setup.outputs.COMMIT_MSG }}\""]() ```${{ github.event.commits[0].message }}```' + + check_for_update: + name: Check for Updates + runs-on: ubuntu-latest + outputs: + run_job: ${{ steps.check_files.outputs.run_job }} + steps: + - uses: actions/checkout@v2 + + - name: Setup Node + uses: actions/setup-node@v2 + with: + node-version: 16 + cache: 'yarn' + + - name: Install NPM Dependencies + run: yarn install --prefer-offline --frozen-lockfile --ignore-engines + env: + CI: true + + - name: Check Modified + run: yarn changeset status --output ./status.json + + - name: Check Output + id: check_files + run: | + output=`echo $(cat status.json)` + if [[ $output = '{ "changesets": [], "releases": [] }' ]] + then + echo 'No changeset found' + echo "::set-output name=run_job::true" + else + echo 'changes found, push to latest skipped' + echo "::set-output name=run_job::false" + fi + + update: + name: Update the latest branch + needs: check_for_update + if: needs.check_for_update.outputs.run_job == 'true' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Push + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: latest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index e1711d20f..000000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: Changelog - -on: - push: - branches: - - main - -jobs: - release: - name: Changelog - runs-on: ubuntu-latest - steps: - - name: Check out code using Git - uses: actions/checkout@v2 - with: - fetch-depth: 0 # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits - - - name: Set Node version to 14 - uses: actions/setup-node@v2 - with: - node-version: 14.x - cache: 'yarn' - - - name: Install dependencies - run: yarn --frozen-lockfile --ignore-engines - env: - CI: true - - - name: Create Release Pull Request or Publish to npm - id: changesets - uses: changesets/action@master - with: - # This expects you to have a script called release which does a build for your packages and calls changeset publish - publish: yarn release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - - - name: Send a Discord notification if a publish happens - if: steps.changesets.outputs.published == 'true' - id: discord-notification - env: - DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} - uses: Ilshidur/action-discord@0.3.2 - with: - args: 'A new release just went out! [Release notes →]()' - - - name: push main branch to latest branch - if: steps.changesets.outputs.published == 'true' - id: git-push-latest - # Note: this will fail if "latest" and "main" have different commit history, - # which is a good thing! Also, don't push if in pre-release mode. - run: '(test -f .changeset/pre.json && echo "prerelease: skip pushing to latest branch.") || git push origin main:latest' diff --git a/.github/workflows/stat.yml b/.github/workflows/stat.yml index e00cf90f1..da0c629f6 100644 --- a/.github/workflows/stat.yml +++ b/.github/workflows/stat.yml @@ -7,7 +7,7 @@ on: jobs: stat: - if: github.repository == 'withastro/astro' + if: github.repository_owner == 'withastro' runs-on: ubuntu-latest steps: - name: Check out code using Git diff --git a/.github/workflows/updatelatest.yml b/.github/workflows/updatelatest.yml deleted file mode 100644 index 635334fbc..000000000 --- a/.github/workflows/updatelatest.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: 'Update Latest from main' - -on: - push: - branches: - - "main" - -env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - -jobs: - update: - name: check for updates in .changeset - runs-on: ubuntu-latest - outputs: - run_job: ${{ steps.check_files.outputs.run_job }} - steps: - - name: checkout git branch - uses: actions/checkout@v2 - - - name: Install all dependencies - run: yarn - - - name: check modified files - run: npx changeset status --output ./status.json - - - name: check output - id: check_files - run: | - output=`echo $(cat status.json)` - if [[ $output = '{ "changesets": [], "releases": [] }' ]] - then - echo 'No changeset found' - echo "::set-output name=run_job::true" - else - echo 'changes found, push to latest skipped' - echo "::set-output name=run_job::false" - fi - - - update_latest_branch: - name: Update the latest branch - needs: update - if: needs.update.outputs.run_job == 'true' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - name: Push - uses: ad-m/github-push-action@master - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - branch: latest \ No newline at end of file diff --git a/package.json b/package.json index ec761fef9..c446a3f87 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ }, "dependencies": {}, "devDependencies": { + "@changesets/changelog-github": "^0.4.2", "@changesets/cli": "^2.16.0", "@octokit/action": "^3.15.4", "@typescript-eslint/eslint-plugin": "^5.0.0", diff --git a/packages/astro-parser/src/parse/index.ts b/packages/astro-parser/src/parse/index.ts index 776d46e2b..e978fe0bc 100644 --- a/packages/astro-parser/src/parse/index.ts +++ b/packages/astro-parser/src/parse/index.ts @@ -29,7 +29,7 @@ export class Parser { js: Script[] = []; meta_tags = {}; last_auto_closed_tag?: LastAutoClosedTag; - feature_flags: number = 0; + feature_flags = 0; constructor(template: string, options: ParserOptions) { if (typeof template !== 'string') { diff --git a/scripts/notify/index.js b/scripts/notify/index.js new file mode 100755 index 000000000..ea911f61a --- /dev/null +++ b/scripts/notify/index.js @@ -0,0 +1,25 @@ +const path = require('path'); +const baseUrl = new URL('https://github.com/withastro/astro/blob/main/'); + +async function run() { + const releases = process.argv.slice(2)[0]; + const data = JSON.parse(releases); + const packages = await Promise.all( + data.map(({ name, version }) => { + const p = path.relative('./', path.dirname(require.resolve(name))).replace(path.sep, '/'); + return { name, version, url: new URL(`${p}/CHANGELOG.md#${version.replace(/\./g, '')}`, baseUrl).toString() }; + }) + ); + + if (packages.length === 1) { + const { name, version, url } = packages[0]; + console.log(`\`${name}@${version}\` was just released! Read the [release notes →](<${url}>)`); + } else { + console.log(`**Some new releases just went out!**\n`); + for (const { name, version, url } of packages) { + console.log(` • \`${name}@${version}\` ([Release Notes →](<${url}>))`); + } + } +} + +run(); diff --git a/yarn.lock b/yarn.lock index f9d43a97e..5435683f6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1142,6 +1142,15 @@ "@manypkg/get-packages" "^1.0.1" semver "^5.4.1" +"@changesets/changelog-github@^0.4.2": + version "0.4.2" + resolved "https://registry.yarnpkg.com/@changesets/changelog-github/-/changelog-github-0.4.2.tgz#359eb4b7485eddc55855f8793811817d5124dfab" + integrity sha512-qq8lJcq91ki7UT0fIfIcn5Yy7GJj19TmkLmGZ24/wEfxcD/nHHoTNRoi6nPt+Htf7qEudKxXLzQLi41B7Mt2vg== + dependencies: + "@changesets/get-github-info" "^0.5.0" + "@changesets/types" "^4.0.2" + dotenv "^8.1.0" + "@changesets/cli@^2.16.0": version "2.18.0" resolved "https://registry.yarnpkg.com/@changesets/cli/-/cli-2.18.0.tgz#662e27c78897cf948ca61177df9c915d750b8221" @@ -1209,6 +1218,14 @@ fs-extra "^7.0.1" semver "^5.4.1" +"@changesets/get-github-info@^0.5.0": + version "0.5.0" + resolved "https://registry.yarnpkg.com/@changesets/get-github-info/-/get-github-info-0.5.0.tgz#b91ceb2d82edef78ae1598ea9fc335a012250295" + integrity sha512-vm5VgHwrxkMkUjFyn3UVNKLbDp9YMHd3vMf1IyJoa/7B+6VpqmtAaXyDS0zBLfN5bhzVCHrRnj4GcZXXcqrFTw== + dependencies: + dataloader "^1.4.0" + node-fetch "^2.5.0" + "@changesets/get-release-plan@^3.0.2": version "3.0.2" resolved "https://registry.yarnpkg.com/@changesets/get-release-plan/-/get-release-plan-3.0.2.tgz#7e5b264838032b226263f8bfeff4706c255f6d4f" @@ -1284,6 +1301,11 @@ resolved "https://registry.yarnpkg.com/@changesets/types/-/types-4.0.1.tgz#85cf3cc32baff0691112d9d15fc21fbe022c9f0a" integrity sha512-zVfv752D8K2tjyFmxU/vnntQ+dPu+9NupOSguA/2Zuym4tVxRh0ylArgKZ1bOAi2eXfGlZMxJU/kj7uCSI15RQ== +"@changesets/types@^4.0.2": + version "4.0.2" + resolved "https://registry.yarnpkg.com/@changesets/types/-/types-4.0.2.tgz#d20e1e45bdc96a97cc509c655e708b53a9292465" + integrity sha512-OeDaB7D+WVy/ErymPzFm58IeGvz4DOl+oedyZETfnkfMezF/Uhrm1Ub6MHrO5LcAaQTW+ptDmr0fmaVyoTxgHw== + "@changesets/write@^0.1.5": version "0.1.5" resolved "https://registry.yarnpkg.com/@changesets/write/-/write-0.1.5.tgz#97574d95c8e48c3bbb1173802672f9a64d1b7fef" @@ -4310,6 +4332,11 @@ data-uri-to-buffer@^4.0.0: resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz#b5db46aea50f6176428ac05b73be39a57701a64b" integrity sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA== +dataloader@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/dataloader/-/dataloader-1.4.0.tgz#bca11d867f5d3f1b9ed9f737bd15970c65dff5c8" + integrity sha512-68s5jYdlvasItOJnCuI2Q9s4q98g0pCyL3HrcKJu8KNugUl8ahgmZYg38ysLTgQjjXX3H8CJLkAvWrclWfcalw== + dateformat@^3.0.0: version "3.0.3" resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-3.0.3.tgz#a6e37499a4d9a9cf85ef5872044d62901c9889ae" @@ -4591,7 +4618,7 @@ dotenv-expand@^5.1.0: resolved "https://registry.yarnpkg.com/dotenv-expand/-/dotenv-expand-5.1.0.tgz#3fbaf020bfd794884072ea26b1e9791d45a629f0" integrity sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA== -dotenv@^8.2.0: +dotenv@^8.1.0, dotenv@^8.2.0: version "8.6.0" resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.6.0.tgz#061af664d19f7f4d8fc6e4ff9b584ce237adcb8b" integrity sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g== @@ -8265,7 +8292,7 @@ node-fetch@*, node-fetch@^3.0.0: fetch-blob "^3.1.2" formdata-polyfill "^4.0.10" -node-fetch@^2.6.0, node-fetch@^2.6.1: +node-fetch@^2.5.0, node-fetch@^2.6.0, node-fetch@^2.6.1: version "2.6.6" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.6.tgz#1751a7c01834e8e1697758732e9efb6eeadfaf89" integrity sha512-Z8/6vRlTUChSdIgMa51jxQ4lrw/Jy5SOW10ObaA47/RElsAN2c5Pn8bTgFGWn/ibwzXTE8qwr1Yzx28vsecXEA==