Files
openapi-clean-arch-gen/.gitea/workflows/publish.yml

110 lines
3.9 KiB
YAML

name: Publish
on:
push:
tags:
- 'v*'
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cache Bun binary
uses: actions/cache@v4
with:
path: ~/.bun
key: bun-v1.3.3-${{ runner.os }}
- name: Setup Bun
run: |
if ! [ -f "$HOME/.bun/bin/bun" ]; then
curl -fsSL https://bun.sh/install | bash -s "bun-v1.3.3"
fi
echo "$HOME/.bun/bin" >> $GITHUB_PATH
- name: Set version from tag
run: |
VERSION=${GITHUB_REF_NAME#v}
echo "Setting package version to $VERSION"
bun -e "const fs=require('fs'); const pkg=JSON.parse(fs.readFileSync('package.json','utf8')); pkg.version='${VERSION}'; fs.writeFileSync('package.json',JSON.stringify(pkg,null,2)+'\n');"
SHA=$(curl -s -H "Authorization: token ${GITEA_TOKEN}" \
"https://git.blassanto.me/api/v1/repos/blas/openapi-clean-arch-gen/contents/package.json?ref=main" \
| bun -e "let d='';process.stdin.on('data',c=>d+=c).on('end',()=>console.log(JSON.parse(d).sha))")
CONTENT=$(base64 -w 0 package.json)
curl -s -X PUT \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
"https://git.blassanto.me/api/v1/repos/blas/openapi-clean-arch-gen/contents/package.json" \
-d "{\"message\":\"chore: bump to version v${VERSION}\",\"content\":\"${CONTENT}\",\"sha\":\"${SHA}\",\"branch\":\"main\"}"
env:
GITEA_TOKEN: ${{ secrets.TOKEN }}
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ~/.bun/install/cache
key: ${{ runner.os }}-bun-deps-${{ hashFiles('bun.lock') }}
restore-keys: |
${{ runner.os }}-bun-deps-
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Lint
run: bun run lint
- name: Build
run: bun run build
- name: Build binaries
run: bun run binaries
- name: Configure npm registry auth
run: |
echo "registry=https://registry.npmjs.org" >> ~/.npmrc
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" >> ~/.npmrc
cat >> ~/.bunfig.toml << EOF
[install.scopes]
"@0kmpo" = { registry = "https://registry.npmjs.org", token = "${NODE_AUTH_TOKEN}" }
EOF
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish to npm registry
run: bun publish --access public
env:
BUN_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create Gitea release and upload binaries
run: |
VERSION=${GITHUB_REF_NAME#v}
RELEASE_ID=$(curl -s -X POST \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
"https://git.blassanto.me/api/v1/repos/blas/openapi-clean-arch-gen/releases" \
-d "{
\"tag_name\": \"${GITHUB_REF_NAME}\",
\"name\": \"v${VERSION}\",
\"body\": \"## Installation\n\nDownload the binary for your platform or install via the npm registry:\n\n\`\`\`bash\nbun add -g @0kmpo/openapi-clean-arch-generator\n\`\`\`\",
\"draft\": false,
\"prerelease\": false
}" | bun -e "let d='';process.stdin.on('data',c=>d+=c).on('end',()=>console.log(JSON.parse(d).id))")
echo "Created release ID: $RELEASE_ID"
for BINARY in dist/bin/*; do
FILENAME=$(basename "$BINARY")
echo "Uploading $FILENAME..."
curl -s -X POST \
-H "Authorization: token ${GITEA_TOKEN}" \
-F "attachment=@${BINARY};filename=${FILENAME}" \
"https://git.blassanto.me/api/v1/repos/blas/openapi-clean-arch-gen/releases/${RELEASE_ID}/assets"
done
env:
GITEA_TOKEN: ${{ secrets.TOKEN }}