Skip to content

Merge pull request #295 from hectorm/dependabot/npm_and_yarn/esbuild-… #979

Merge pull request #295 from hectorm/dependabot/npm_and_yarn/esbuild-…

Merge pull request #295 from hectorm/dependabot/npm_and_yarn/esbuild-… #979

Workflow file for this run

name: 'Main'
on:
push:
tags: ['*']
branches: ['*']
pull_request:
branches: ['*']
schedule:
- cron: '25 12 * * 3'
workflow_dispatch:
permissions: {}
jobs:
lint:
name: 'Lint'
runs-on: 'ubuntu-latest'
permissions:
contents: 'read'
env:
NODE_VERSION: 'lts/*'
steps:
- name: 'Checkout'
uses: 'actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9'
- name: 'Use Node.js ${{ env.NODE_VERSION }}'
uses: 'actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8'
with:
node-version: '${{ env.NODE_VERSION }}'
cache: 'npm'
- name: 'Upgrade npm'
run: 'npm install -g npm@latest'
- name: 'Install'
run: 'npm ci'
- name: 'Lint'
run: 'npm run lint'
test:
name: 'Test on Node.js ${{ matrix.node_version }} and ${{ matrix.os }}'
needs: ['lint']
runs-on: '${{ matrix.os }}'
permissions:
contents: 'read'
strategy:
matrix:
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
node_version: ['lts/-1', 'lts/*', 'current']
steps:
- name: 'Checkout'
uses: 'actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9'
- name: 'Use Node.js ${{ matrix.node_version }}'
uses: 'actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8'
with:
node-version: '${{ matrix.node_version }}'
cache: 'npm'
- name: 'Upgrade npm'
run: 'npm install -g npm@latest'
- name: 'Install'
run: 'npm ci'
- name: 'Test'
run: 'npm run test'
build:
name: 'Build'
needs: ['test']
runs-on: 'ubuntu-latest'
permissions:
contents: 'read'
env:
NODE_VERSION: 'lts/*'
steps:
- name: 'Checkout'
uses: 'actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9'
- name: 'Use Node.js ${{ env.NODE_VERSION }}'
uses: 'actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8'
with:
node-version: '${{ env.NODE_VERSION }}'
cache: 'npm'
- name: 'Upgrade npm'
run: 'npm install -g npm@latest'
- name: 'Install'
run: 'npm ci'
- name: 'Build'
run: |
npm run build && npm run build-binary
for f in ./dist/*-linuxstatic-*; do gzip -n "${f:?}"; done
for f in ./dist/*-win-*.exe; do zip -mj "${f:?}.zip" "${f:?}"; done
- name: 'Upload artifacts'
uses: 'actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce'
with:
name: 'dist'
path: |
./dist/*.js
./dist/*.gz
./dist/*.zip
retention-days: 1
build-push-docker:
name: 'Build and push Docker images'
needs: ['build']
runs-on: 'ubuntu-latest'
permissions:
contents: 'read'
packages: 'write'
steps:
- name: 'Checkout'
uses: 'actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9'
- name: 'Set up QEMU'
uses: 'docker/setup-qemu-action@2b82ce82d56a2a04d2637cd93a637ae1b359c0a7'
- name: 'Set up Docker Buildx'
uses: 'docker/setup-buildx-action@4c0219f9ac95b02789c1075625400b2acbff50b1'
- name: 'Login to GitHub Container Registry'
if: "github.event_name != 'pull_request'"
uses: 'docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc'
with:
registry: 'ghcr.io'
username: '${{ github.actor }}'
password: '${{ secrets.GITHUB_TOKEN }}'
- name: 'Login to Docker Hub'
if: "github.event_name != 'pull_request'"
uses: 'docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc'
with:
registry: 'docker.io'
username: '${{ secrets.DOCKERHUB_USERNAME }}'
password: '${{ secrets.DOCKERHUB_TOKEN }}'
- name: 'Extract metadata'
id: 'meta'
uses: 'docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175'
with:
images: |
ghcr.io/${{ github.repository }}
docker.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=semver,pattern=v{{version}}
type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern=v{{major}}
- name: 'Build and push'
uses: 'docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825'
with:
context: './'
platforms: 'linux/amd64,linux/arm64'
tags: '${{ steps.meta.outputs.tags }}'
labels: '${{ steps.meta.outputs.labels }}'
push: "${{ github.event_name != 'pull_request' }}"
publish-npm:
name: 'Publish npm package'
if: "startsWith(github.ref, 'refs/tags/v')"
needs: ['build', 'build-push-docker']
runs-on: 'ubuntu-latest'
permissions:
contents: 'read'
env:
NODE_VERSION: 'lts/*'
steps:
- name: 'Checkout'
uses: 'actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9'
- name: 'Use Node.js ${{ env.NODE_VERSION }}'
uses: 'actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8'
with:
node-version: '${{ env.NODE_VERSION }}'
registry-url: 'https://registry.npmjs.org'
- name: 'Upgrade npm'
run: 'npm install -g npm@latest'
- name: 'Publish package'
env:
NODE_AUTH_TOKEN: '${{ secrets.NPM_TOKEN }}'
run: |
PKG_NAME="$(jq -r '.name' ./package.json)"; PKG_VERSION="$(jq -r '.version' ./package.json)"
if [ "$(npm view "${PKG_NAME:?}" versions --json | jq -r --arg v "${PKG_VERSION:?}" 'index($v)')" = 'null' ]; then
npm publish
fi
release-github:
name: 'Create GitHub release'
if: "startsWith(github.ref, 'refs/tags/v')"
needs: ['build', 'build-push-docker']
runs-on: 'ubuntu-latest'
permissions:
contents: 'write'
steps:
- name: 'Download artifacts'
uses: 'actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a'
with:
name: 'dist'
- name: 'Create release'
env:
GITHUB_PAT: '${{ secrets.GITHUB_TOKEN }}'
run: |
RELEASE_STATUS="$(curl -fs --proto '=https' --tlsv1.3 --globoff \
--url "https://api.github.com/repos/${GITHUB_REPOSITORY:?}/releases/tags/${GITHUB_REF_NAME:?}" \
--header "Authorization: Bearer ${GITHUB_PAT:?}" \
--header 'Accept: application/vnd.github.v3+json' \
--header 'Content-Type: application/json' \
--write-out '%{http_code}' --output /dev/null ||:)"
if [ "${RELEASE_STATUS:?}" = '200' ]; then exit 0; fi
RELEASE_ID="$(curl -fsS --proto '=https' --tlsv1.3 --globoff \
--url "https://api.github.com/repos/${GITHUB_REPOSITORY:?}/releases" \
--header "Authorization: Bearer ${GITHUB_PAT:?}" \
--header 'Accept: application/vnd.github.v3+json' \
--header 'Content-Type: application/json' \
--data "$(jq -rn --arg tag "${GITHUB_REF_NAME:?}" '{"name": $tag, "tag_name": $tag, "generate_release_notes": true}')" | jq -r '.id')"
if [ -z "${RELEASE_ID-}" ] || [ "${RELEASE_ID:?}" = 'null' ]; then exit 1; fi
for asset in ./*; do
[ -f "${asset:?}" ] || continue
encodedAssetName="$(jq -rn --arg v "$(basename "${asset:?}")" '$v|@uri')"
curl -fsS --proto '=https' --tlsv1.3 --globoff \
--url "https://uploads.github.com/repos/${GITHUB_REPOSITORY:?}/releases/${RELEASE_ID:?}/assets?name=${encodedAssetName:?})" \
--header "Authorization: Bearer ${GITHUB_PAT:?}" \
--header 'Accept: application/vnd.github.v3+json' \
--header 'Content-Type: application/octet-stream' \
--data-binary "@${asset:?}" --output /dev/null
done