Skip to content

Commit

Permalink
Add GitHub actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Aerilius committed May 9, 2024
1 parent ceee5f1 commit d36adc5
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 0 deletions.
99 changes: 99 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Release

on:
release:
types:
- published

jobs:

build:
name: Build release artifacts
permissions:
contents: write
runs-on: ubuntu-latest
steps:

- name: Checkout repository
uses: actions/checkout@v4

- name: Use Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 18
registry-url: https://registry.npmjs.org/

- name: Install Ruby dependencies
run: bundle install

- name: Install Node dependencies
run: npm ci

- name: Build JavaScript library
run: npm run build

- name: Build distributable Ruby library
run: bundle exec rake build_dist

- name: Build sample SketchUp extension
run: bundle exec rake build_sample_extension

- name: Build tutorial SketchUp extension
run: bundle exec rake build_tutorial_rbz

- name: Include built files in repository
uses: devops-infra/action-commit-push@master
with:
github_token: "${{ secrets.GITHUB_TOKEN }}"
commit_message: "[AUTO] Update sample files"
force: false
target_branch: main

- name: Add tutorial SketchUp extension to release
uses: actions/github-script@v7
env:
path: ae_bridgelibrary*.rbz
with:
script: |
// From https://til.simonwillison.net/github-actions/attach-generated-file-to-release
const fs = require('fs')
const path = require('path')
// Resolve any wildcards with glob (by default included from @actions/glob)
const globber = await glob.create(process.env.path)
const assetPath = (await globber.glob())[0]
// Get release for this tag
const tag = context.ref.replace('refs/tags/', '')
const release = await github.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag
})
// Upload the release asset
await github.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.data.id,
name: path.basename(assetPath),
data: await fs.readFileSync(assetPath)
})
publish-npm:
name: Publish JavaScript library on NPM
# We could specify `needs: build` and publish the compiled code (as in <=3.0.7)
# but the source is more useful for development and optimization of other SketchUp plugins.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
32 changes: 32 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:

build-javascript:
name: Build JavaScript library
runs-on: ubuntu-latest
steps:

- name: Checkout repository
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Build JavaScript library
run: npm run dev

- name: Run JavaScript tests
run: npm run test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ node_modules
.yardoc
doc

# Exclude built SketchUp extension
*.rbz

0 comments on commit d36adc5

Please sign in to comment.