Skip to content

Merge pull request #254 from hectorm/dependabot/npm_and_yarn/babel/co… #868

Merge pull request #254 from hectorm/dependabot/npm_and_yarn/babel/co…

Merge pull request #254 from hectorm/dependabot/npm_and_yarn/babel/co… #868

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@8e5e7e5ab8b370d6c329ec480221332ada57f0ab'
- name: 'Use Node.js ${{ env.NODE_VERSION }}'
uses: 'actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c'
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@8e5e7e5ab8b370d6c329ec480221332ada57f0ab'
- name: 'Use Node.js ${{ matrix.node_version }}'
uses: 'actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c'
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@8e5e7e5ab8b370d6c329ec480221332ada57f0ab'
- name: 'Use Node.js ${{ env.NODE_VERSION }}'
uses: 'actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c'
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@8e5e7e5ab8b370d6c329ec480221332ada57f0ab'
- name: 'Set up QEMU'
uses: 'docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18'
- name: 'Set up Docker Buildx'
uses: 'docker/setup-buildx-action@4b4e9c3e2d4531116a6f8ba8e71fc6e2cb6e6c8c'
- name: 'Login to GitHub Container Registry'
if: "github.event_name != 'pull_request'"
uses: 'docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a'
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@f4ef78c080cd8ba55a85445d5b36e214a81df20a'
with:
registry: 'docker.io'
username: '${{ secrets.DOCKERHUB_USERNAME }}'
password: '${{ secrets.DOCKERHUB_TOKEN }}'
- name: 'Extract metadata'
id: 'meta'
uses: 'docker/metadata-action@c4ee3adeed93b1fa6a762f209fb01608c1a22f1e'
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@3b5e8027fcad23fda98b2e3ac259d8d67585f671'
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@8e5e7e5ab8b370d6c329ec480221332ada57f0ab'
- name: 'Use Node.js ${{ env.NODE_VERSION }}'
uses: 'actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c'
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