feat: add sqlc.embed support, run format #31
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: ci | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
jobs: | |
build_and_test: | |
services: | |
postgres: | |
image: postgres | |
env: | |
POSTGRES_USER: test | |
POSTGRES_PASSWORD: test | |
POSTGRES_DB: test | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
ports: | |
- 5439:5432 | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: sqlc-dev/setup-sqlc@v4 | |
with: | |
sqlc-version: '1.27.0' | |
- uses: oven-sh/setup-bun@v2 | |
- run: wget https://github.com/bytecodealliance/javy/releases/download/v4.0.0/javy-x86_64-linux-v4.0.0.gz | |
- run: gzip -d javy-x86_64-linux-v4.0.0.gz | |
- run: chmod +x javy-x86_64-linux-v4.0.0 | |
- run: bun install | |
- run: bun build --entrypoints ./src/app.ts --outfile=out.js --minify --target browser | |
- run: ./javy-x86_64-linux-v4.0.0 build out.js -o plugin.wasm | |
- name: Run tests | |
run: cd test && bun run test | |
- id: calculate_sha256 | |
run: | | |
sha256sum plugin.wasm > plugin.wasm.sha256 | |
SHA256=$(cat plugin.wasm.sha256 | awk '{ print $1 }') | |
echo "::set-output name=sha256::$SHA256" | |
- name: Set outputs | |
id: vars | |
run: echo "tag_name=v$(date +'%Y%m%d.%H%M%S')_$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
- name: Create GitHub Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.vars.outputs.tag_name }} | |
release_name: Nightly Release | |
draft: false | |
prerelease: false | |
- name: Upload Plugin WASM to Release | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: plugin.wasm | |
asset_name: plugin.wasm | |
asset_content_type: application/wasm | |
- name: Upload Plugin WASM SHA256 to Release | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: plugin.wasm.sha256 | |
asset_name: plugin.wasm.sha256 | |
asset_content_type: text/plain | |
- name: Update Release Description with SHA256 and Commits | |
uses: actions/github-script@v4 | |
env: | |
tag: ${{ steps.vars.outputs.tag_name }} | |
sha256: ${{ steps.calculate_sha256.outputs.sha256 }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
script: | | |
const { tag, sha256 } = process.env; | |
// Retrieve all releases to identify current and previous releases | |
const { data: releases } = await github.repos.listReleases({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
}); | |
// Find the current release | |
const currentRelease = releases.find(r => r.tag_name === tag); | |
if (!currentRelease) { | |
throw new Error(`Cannot find release for tag ${tag}`); | |
} | |
// Sort releases by creation date, descending | |
const sortedReleases = releases.sort((a, b) => new Date(b.created_at) - new Date(a.created_at)); | |
// Find the current release index, then take the next release as the previous | |
const currentIndex = sortedReleases.findIndex(r => r.id === currentRelease.id); | |
const previousRelease = sortedReleases[currentIndex + 1]; | |
let commitsDescription = ""; | |
// If theres a previous release, compare commits; otherwise note that no previous release was found | |
if (previousRelease) { | |
const { data: compare } = await github.repos.compareCommits({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
base: previousRelease.tag_name, | |
head: tag | |
}); | |
// Build a simple list of commit messages and short SHAs | |
commitsDescription = compare.commits | |
.map(commit => `- ${commit.commit.message} (${commit.sha.substring(0, 7)})`) | |
.join("\n"); | |
} else { | |
commitsDescription = "No previous release found."; | |
} | |
// Retrieve the current release details by its tag | |
const { data: release } = await github.repos.getReleaseByTag({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag: tag | |
}); | |
// Construct the new body with plugin info and commit list | |
const newBody = `\`\`\`yml | |
plugins: | |
- name: ts | |
wasm: | |
url: https://github.com/eEQK/sqlc-gen-typescript/releases/download/${tag}/plugin.wasm | |
sha256: ${sha256} | |
\`\`\` | |
Commits since last release: | |
${commitsDescription} | |
`; | |
// Update the release description | |
await github.repos.updateRelease({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
release_id: release.id, | |
body: newBody | |
}); |