Skip to content

Initial commit

Initial commit #1

Workflow file for this run

name: Initial setup
on:
push:
permissions: write-all
jobs:
setup:
runs-on: ubuntu-latest
if: "!github.event.repository.is_template"
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install tree-sitter CLI
uses: tree-sitter/setup-action/cli@v1
with:
tree-sitter-ref: f8c41f7
- name: Remove template files
run: rm .gitattributes .github/workflows/setup.yml
- name: Generate bindings
run: tree-sitter generate
- name: Set environment variables
run: |-
printf 'PARSER_NAME=%s\n' $(jq -r '.keywords[3]' package.json) >> "$GITHUB_ENV"
if [[ -n $AUTHOR_EMAIL && ${AUTHOR_EMAIL#*@} != users.noreply.github.com ]]; then
AUTHOR_NAME_EMAIL="$AUTHOR_NAME <$AUTHOR_EMAIL>"
fi
printf >> "$GITHUB_ENV" '%s\n' \
"AUTHOR_NAME=$AUTHOR_NAME" \
"AUTHOR_EMAIL=$AUTHOR_EMAIL" \
"AUTHOR_NAME_EMAIL=${AUTHOR_NAME_EMAIL:-$AUTHOR_NAME}"
env:
AUTHOR_NAME: ${{github.event.head_commit.author.name}}
AUTHOR_EMAIL: ${{github.event.head_commit.author.email}}
- name: Update files
run: |-
sed -i README.md -e 's/PARSER_NAME/${{env.PARSER_NAME}}/'
sed -i LICENSE -e 's/AUTHOR_NAME/${{env.AUTHOR_NAME}}/'
sed -i grammar.js \
-e 's/TODO:/NOTE:/' \
-e 's/source_file.*/changeme: $ => "",/'
sed -i package.json \
-e '/"scope"/a \ "highlights": "queries/highlights.scm",' \
-e '/"repository"/a \ "author": "${{env.AUTHOR_NAME_EMAIL}}",' \
-e '/"repository"/s|github:.*"|github:${{github.repository}}"|'
sed -i Cargo.toml \
-e '/^repository/a authors = ["${{env.AUTHOR_NAME_EMAIL}}"]' \
-e '/^repository/s|/tree-sitter/.*|/${{github.repository}}"|'
sed -i pyproject.toml \
-e '/^classifiers/i authors = [' \
-e '/^classifiers/i ]' \
-e '/^Homepage/s|/tree-sitter/.*|/${{github.repository}}"|'
if [[ $AUTHOR_NAME_EMAIL == $AUTHOR_NAME ]]; then
sed -i pyproject.toml \
-e '/^authors/a \ {name = "${{env.AUTHOR_NAME}}}"}'
else
sed -i pyproject.toml \
-e '/^authors/a \ {name = "${{env.AUTHOR_NAME}}}", email = "${{env.AUTHOR_EMAIL}}"}'
fi
sed -i Makefile \
-e '/^PARSER_REPO_URL/i PARSER_URL := https://github.com/${{github.repository}}'
sed -i bindings/rust/lib.rs \
-e '/Uncomment these/s/Uncomment.*/NOTE: \l&:/'
sed -i bindings/go/binding_test.go \
-e 's|/tree-sitter/.*|/${{github.repository}}"|'
env:
REPO_OWNER: ${{github.repository_owner}}
REPO_NAME: ${{github.event.repository.name}}
- name: Update commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_user_name: ${{github.event.head_commit.author.username}}
commit_user_email: ${{github.event.head_commit.author.email}}
commit_message: "feat: initial commit"
commit_options: --amend
push_options: --force
skip_fetch: true
- name: Add next steps to summary
run: |-
printf >> "$GITHUB_STEP_SUMMARY" '%s\n' \
'The repository has been set up successfully.' \
'You can now clone and configure it like so:' \
'' \
'~~~bash' \
'git clone ${{github.server_url}}/${{github.repository}}' \
'cd ${{github.event.repository.name}}' \
'gh repo edit \' \
' --enable-merge-commit=false \' \
' --enable-discussions=false \' \
' --enable-projects=false \' \
' --enable-wiki=false \' \
' --add-topic=tree-sitter \' \
' --add-topic=parser \' \
' --add-topic=${{env.PARSER_NAME}} \' \
" -d '$(jq -r .description package.json)'" \
'~~~'