Skip to content

Build and Release

Build and Release #73

Workflow file for this run

name: Build and Release
on:
schedule:
- cron: '0 6 * * *'
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
exists: ${{ steps.check_release.outputs.exists }}
steps:
- uses: actions/checkout@v6
with:
persist-credentials: false
- uses: actions/setup-node@v6
with:
node-version: '24'
package-manager-cache: false
- run: npm ci
- run: npm test
- run: npm run build
- name: Get version
id: version
run: |
MAJOR_MINOR=$(node -p "require('./package.json').version.split('.').slice(0,2).join('.')")
echo "version=${MAJOR_MINOR}.$(date -u +%Y%m%d)" >> $GITHUB_OUTPUT
echo "tag=v${MAJOR_MINOR}.$(date -u +%Y%m%d)" >> $GITHUB_OUTPUT
- name: Compress database
run: gzip -k critical-packages.db
- name: Upload artifacts
uses: actions/upload-artifact@v6
with:
name: database
path: |
critical-packages.db
critical-packages.db.gz
- name: Check if release exists
id: check_release
env:
TAG: ${{ steps.version.outputs.tag }}
run: |
if git ls-remote --tags origin | grep -q "refs/tags/$TAG"; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Create release
if: steps.check_release.outputs.exists == 'false'
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.version.outputs.tag }}
name: ${{ steps.version.outputs.tag }}
files: |
critical-packages.db
critical-packages.db.gz
body: |
Daily build of critical packages database.
Download the `.db` file for uncompressed SQLite, or `.db.gz` for compressed.
Also available via npm: `npm install @ecosyste-ms/critical@${{ steps.version.outputs.version }}`
publish:
needs: build
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v6
with:
persist-credentials: false
- uses: actions/setup-node@v6
with:
node-version: '24'
registry-url: 'https://registry.npmjs.org'
package-manager-cache: false
- name: Download database
uses: actions/download-artifact@v8
with:
name: database
- name: Install latest npm
run: npm install -g npm@latest
- name: Set package version
env:
VERSION: ${{ needs.build.outputs.version }}
run: npm version "$VERSION" --no-git-tag-version
- name: Publish to npm
env:
VERSION: ${{ needs.build.outputs.version }}
run: |
if npm view "@ecosyste-ms/critical@$VERSION" version 2>/dev/null; then
echo "Version $VERSION already published, skipping"
else
npm publish --access public
fi