Merge pull request #2936 from dundargoc/ci/release
ci: rework release strategy
This commit is contained in:
commit
032a1089fd
5 changed files with 85 additions and 211 deletions
66
.github/workflows/CICD.yml
vendored
66
.github/workflows/CICD.yml
vendored
|
|
@ -1,66 +0,0 @@
|
||||||
name: CICD
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
pull_request:
|
|
||||||
types:
|
|
||||||
- opened
|
|
||||||
- reopened
|
|
||||||
- synchronize
|
|
||||||
- ready_for_review
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- 'master'
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
|
||||||
cancel-in-progress: true
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
init:
|
|
||||||
name: Init
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Get PR head ref
|
|
||||||
if: ${{ github.event_name == 'pull_request' }}
|
|
||||||
id: pr_head_ref
|
|
||||||
run: |
|
|
||||||
echo "ref=refs/pull/${{ github.event.pull_request.number }}/head" >> $GITHUB_OUTPUT
|
|
||||||
outputs:
|
|
||||||
ref: >-
|
|
||||||
${{
|
|
||||||
(github.event_name == 'pull_request' && startsWith(github.head_ref, 'release/v'))
|
|
||||||
&& steps.pr_head_ref.outputs.ref
|
|
||||||
|| github.ref
|
|
||||||
}}
|
|
||||||
|
|
||||||
checks:
|
|
||||||
uses: ./.github/workflows/checks.yml
|
|
||||||
|
|
||||||
sanitize:
|
|
||||||
name: Sanitize
|
|
||||||
needs: [init, checks]
|
|
||||||
uses: ./.github/workflows/sanitize.yml
|
|
||||||
|
|
||||||
build:
|
|
||||||
name: Build & Test
|
|
||||||
needs: [init, checks]
|
|
||||||
uses: ./.github/workflows/build.yml
|
|
||||||
with:
|
|
||||||
ref: ${{ needs.init.outputs.ref }}
|
|
||||||
|
|
||||||
release:
|
|
||||||
name: Release
|
|
||||||
needs: [init, checks, build, sanitize]
|
|
||||||
if: >
|
|
||||||
github.event_name == 'pull_request' &&
|
|
||||||
startsWith(github.head_ref, 'release/v') &&
|
|
||||||
!github.event.pull_request.draft
|
|
||||||
uses: ./.github/workflows/release.yml
|
|
||||||
with:
|
|
||||||
ref: ${{ needs.init.outputs.ref }}
|
|
||||||
|
|
||||||
publish:
|
|
||||||
name: Publish
|
|
||||||
needs: release
|
|
||||||
uses: ./.github/workflows/publish.yml
|
|
||||||
23
.github/workflows/build.yml
vendored
23
.github/workflows/build.yml
vendored
|
|
@ -8,9 +8,9 @@ env:
|
||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
inputs:
|
inputs:
|
||||||
ref:
|
run_test:
|
||||||
default: ${{ github.ref }}
|
default: true
|
||||||
type: string
|
type: boolean
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|
@ -71,10 +71,7 @@ jobs:
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout source code
|
- uses: actions/checkout@v4
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
ref: ${{ inputs.ref }}
|
|
||||||
|
|
||||||
- name: Read Emscripten version
|
- name: Read Emscripten version
|
||||||
run: |
|
run: |
|
||||||
|
|
@ -167,27 +164,27 @@ jobs:
|
||||||
echo "🔗 Minimal **glibc** version required for CLI: ${min_glibc}">> $GITHUB_STEP_SUMMARY
|
echo "🔗 Minimal **glibc** version required for CLI: ${min_glibc}">> $GITHUB_STEP_SUMMARY
|
||||||
|
|
||||||
- name: Fetch fixtures
|
- name: Fetch fixtures
|
||||||
if: ${{ !matrix.cli-only }} # Don't fetch fixtures for only CLI building targets
|
if: ${{ !matrix.cli-only && inputs.run_test }} # Don't fetch fixtures for only CLI building targets
|
||||||
run: script/fetch-fixtures
|
run: script/fetch-fixtures
|
||||||
|
|
||||||
- name: Generate fixtures
|
- name: Generate fixtures
|
||||||
if: ${{ !matrix.cli-only }} # Can't natively run CLI on Github runner's host
|
if: ${{ !matrix.cli-only && inputs.run_test }} # Can't natively run CLI on Github runner's host
|
||||||
run: script/generate-fixtures
|
run: script/generate-fixtures
|
||||||
|
|
||||||
- name: Generate WASM fixtures
|
- name: Generate WASM fixtures
|
||||||
if: ${{ !matrix.cli-only && !matrix.use-cross }} # See comment for the "Build wasm library" step
|
if: ${{ !matrix.cli-only && !matrix.use-cross && inputs.run_test }} # See comment for the "Build wasm library" step
|
||||||
run: script/generate-fixtures-wasm
|
run: script/generate-fixtures-wasm
|
||||||
|
|
||||||
- name: Run main tests
|
- name: Run main tests
|
||||||
if: ${{ !matrix.cli-only }} # Can't natively run CLI on Github runner's host
|
if: ${{ !matrix.cli-only && inputs.run_test }} # Can't natively run CLI on Github runner's host
|
||||||
run: $BUILD_CMD test --target=${{ matrix.target }} --features=${CLI_FEATURES}
|
run: $BUILD_CMD test --target=${{ matrix.target }} --features=${CLI_FEATURES}
|
||||||
|
|
||||||
- name: Run wasm tests
|
- name: Run wasm tests
|
||||||
if: ${{ !matrix.cli-only && !matrix.use-cross }} # See comment for the "Build wasm library" step
|
if: ${{ !matrix.cli-only && !matrix.use-cross && inputs.run_test }} # See comment for the "Build wasm library" step
|
||||||
run: script/test-wasm
|
run: script/test-wasm
|
||||||
|
|
||||||
- name: Run benchmarks
|
- name: Run benchmarks
|
||||||
if: ${{ !matrix.cli-only && !matrix.use-cross }} # Cross-compiled benchmarks make no sense
|
if: ${{ !matrix.cli-only && !matrix.use-cross && inputs.run_test }} # Cross-compiled benchmarks make no sense
|
||||||
run: $BUILD_CMD bench benchmark -p tree-sitter-cli --target=${{ matrix.target }}
|
run: $BUILD_CMD bench benchmark -p tree-sitter-cli --target=${{ matrix.target }}
|
||||||
|
|
||||||
- name: Upload CLI artifact
|
- name: Upload CLI artifact
|
||||||
|
|
|
||||||
23
.github/workflows/ci.yml
vendored
Normal file
23
.github/workflows/ci.yml
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'master'
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
checks:
|
||||||
|
uses: ./.github/workflows/checks.yml
|
||||||
|
|
||||||
|
sanitize:
|
||||||
|
needs: checks
|
||||||
|
uses: ./.github/workflows/sanitize.yml
|
||||||
|
|
||||||
|
build:
|
||||||
|
needs: checks
|
||||||
|
uses: ./.github/workflows/build.yml
|
||||||
63
.github/workflows/publish.yml
vendored
63
.github/workflows/publish.yml
vendored
|
|
@ -1,63 +0,0 @@
|
||||||
name: Publish to registries
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_call:
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
crates_io:
|
|
||||||
name: Publish CLI to Crates.io
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Get latest tag
|
|
||||||
id: latest_tag
|
|
||||||
run: |
|
|
||||||
echo "tag=$(git describe --tags `git rev-list --tags --max-count=1`)" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Check out latest tag
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
ref: ${{ steps.latest_tag.outputs.tag }}
|
|
||||||
|
|
||||||
- name: Setup Rust
|
|
||||||
uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
|
||||||
profile: minimal
|
|
||||||
toolchain: stable
|
|
||||||
override: true
|
|
||||||
|
|
||||||
- name: Publish CLI to Crates.io
|
|
||||||
uses: katyo/publish-crates@v2
|
|
||||||
with:
|
|
||||||
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
|
||||||
|
|
||||||
npm:
|
|
||||||
name: Publish lib to npmjs.com
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
directory: ["cli/npm", "lib/binding_web"]
|
|
||||||
steps:
|
|
||||||
- name: Get latest tag
|
|
||||||
id: latest_tag
|
|
||||||
run: |
|
|
||||||
echo "tag=$(git describe --tags `git rev-list --tags --max-count=1`)" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Check out latest tag
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
ref: ${{ steps.latest_tag.outputs.tag }}
|
|
||||||
|
|
||||||
- name: Setup Node
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 18
|
|
||||||
registry-url: "https://registry.npmjs.org"
|
|
||||||
|
|
||||||
- name: Publish lib to npmjs.com
|
|
||||||
env:
|
|
||||||
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
|
||||||
run: |
|
|
||||||
cd ${{ matrix.directory }}
|
|
||||||
npm publish
|
|
||||||
121
.github/workflows/release.yml
vendored
121
.github/workflows/release.yml
vendored
|
|
@ -1,61 +1,24 @@
|
||||||
name: Release
|
name: Release
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_dispatch:
|
||||||
inputs:
|
push:
|
||||||
ref:
|
tags:
|
||||||
default: ${{ github.ref }}
|
- v*
|
||||||
type: string
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
permissions:
|
build:
|
||||||
name: Check permissions
|
uses: ./.github/workflows/build.yml
|
||||||
runs-on: ubuntu-latest
|
with:
|
||||||
outputs:
|
run_test: false
|
||||||
release_allowed: >
|
|
||||||
${{
|
|
||||||
github.repository_owner == 'tree-sitter' &&
|
|
||||||
steps.maintainer.outputs.is_maintainer == 'true' &&
|
|
||||||
steps.local_branch.outputs.is_local == 'true'
|
|
||||||
}}
|
|
||||||
steps:
|
|
||||||
|
|
||||||
- name: Initated by a maintainer
|
|
||||||
id: maintainer
|
|
||||||
env:
|
|
||||||
GH_TOKEN: ${{ github.token }}
|
|
||||||
repo: ${{ github.repository }}
|
|
||||||
actor: ${{ github.actor }}
|
|
||||||
run: |
|
|
||||||
maintainer=$(
|
|
||||||
gh api "/repos/${repo}/collaborators" |
|
|
||||||
jq ".[] | {login, maintainer: .permissions | .maintain} | select(.login == \"${actor}\") | .maintainer"
|
|
||||||
);
|
|
||||||
if [ "$maintainer" == "true" ]; then
|
|
||||||
echo "@${actor} has maintainer level permissions :rocket:" >> $GITHUB_STEP_SUMMARY;
|
|
||||||
echo "is_maintainer=true" >> $GITHUB_OUTPUT
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: The ref branch is local
|
|
||||||
id: local_branch
|
|
||||||
env:
|
|
||||||
is_local: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
|
|
||||||
run: |
|
|
||||||
echo "is_local=${is_local}" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
name: Release
|
name: Release
|
||||||
needs: permissions
|
|
||||||
if: needs.permissions.outputs.release_allowed
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
needs: build
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
steps:
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
- name: Checkout source code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
ref: ${{ inputs.ref }}
|
|
||||||
|
|
||||||
- name: Download build artifacts
|
- name: Download build artifacts
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
|
|
@ -78,36 +41,56 @@ jobs:
|
||||||
rm -rf artifacts
|
rm -rf artifacts
|
||||||
ls -l target/
|
ls -l target/
|
||||||
|
|
||||||
- name: Get tag name from a release/v* branch name
|
|
||||||
id: tag_name
|
|
||||||
env:
|
|
||||||
tag: ${{ github.head_ref }}
|
|
||||||
run: echo "tag=${tag#release/}" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Add a release tag
|
|
||||||
env:
|
|
||||||
ref: ${{ inputs.ref }}
|
|
||||||
tag: ${{ steps.tag_name.outputs.tag }}
|
|
||||||
message: "Release ${{ steps.tag_name.outputs.tag }}"
|
|
||||||
run: |
|
|
||||||
git config user.name "$(git log -1 --pretty='%cn')"
|
|
||||||
git config user.email "$(git log -1 --pretty='%ce')"
|
|
||||||
git tag -a "$tag" HEAD -m "$message"
|
|
||||||
git push origin "$tag"
|
|
||||||
|
|
||||||
- name: Create release
|
- name: Create release
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v1
|
||||||
with:
|
with:
|
||||||
name: ${{ steps.tag_name.outputs.tag }}
|
name: ${{ github.ref_name }}
|
||||||
tag_name: ${{ steps.tag_name.outputs.tag }}
|
tag_name: ${{ github.ref_name }}
|
||||||
fail_on_unmatched_files: true
|
fail_on_unmatched_files: true
|
||||||
files: |
|
files: |
|
||||||
target/tree-sitter-*.gz
|
target/tree-sitter-*.gz
|
||||||
target/tree-sitter.wasm
|
target/tree-sitter.wasm
|
||||||
target/tree-sitter.js
|
target/tree-sitter.js
|
||||||
|
|
||||||
- name: Merge release PR
|
crates_io:
|
||||||
|
name: Publish CLI to Crates.io
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: release
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Rust
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
toolchain: stable
|
||||||
|
override: true
|
||||||
|
|
||||||
|
- name: Publish CLI to Crates.io
|
||||||
|
uses: katyo/publish-crates@v2
|
||||||
|
with:
|
||||||
|
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
||||||
|
|
||||||
|
npm:
|
||||||
|
name: Publish lib to npmjs.com
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: release
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
directory: ["cli/npm", "lib/binding_web"]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Node
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 18
|
||||||
|
registry-url: "https://registry.npmjs.org"
|
||||||
|
|
||||||
|
- name: Publish lib to npmjs.com
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ github.token }}
|
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
||||||
run: |
|
run: |
|
||||||
gh pr merge ${{ github.event.pull_request.html_url }} --match-head-commit $(git rev-parse HEAD) --merge --delete-branch
|
cd ${{ matrix.directory }}
|
||||||
|
npm publish
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue