Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: merge staging to master #41

Merged
merged 17 commits into from
Jul 10, 2024
268 changes: 268 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
name: CI

on:
push:
branches:
- staging
- feature*

jobs:
check-lint:
name: "Check / Lint"
runs-on: ubuntu-latest
container:
image: ghcr.io/matrixai/github-runner
steps:
- uses: actions/checkout@v4
- name: Run linting
run: |
nix develop --command bash -c $'
npm run lint
npm run lint-shell
'

check-test:
name: "Check / Test"
runs-on: ubuntu-latest
container:
image: ghcr.io/matrixai/github-runner
steps:
- uses: actions/checkout@v4
- name: Run tests
run: |
nix develop .#ci --command bash -c $'
npm run prebuild --verbose
npm test -- --ci --coverage
'
- uses: actions/upload-artifact@v4
with:
name: coverage-report
path: tmp/coverage/cobertura-coverage.xml

build-pull:
name: "Build / Pull Request"
runs-on: ubuntu-latest
needs: [check-lint, check-test]
if: github.ref == 'refs/heads/staging'
steps:
- uses: actions/checkout@v4
- name: Create pull request
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
gh pr create \
--head staging \
--base master \
--title "ci: merge staging to master" \
--body "This is an automatic PR generated by the CI/CD pipeline. This will be automatically fast-forward merged if successful." \
--assignee "@me" \
--no-maintainer-edit || true
printf "Pipeline Attempt on $GITHUB_RUN_ID for $GITHUB_SHA\n\n$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" \
| gh pr comment staging \
--body-file - \
--repo "$GITHUB_REPOSITORY"

build-dist:
name: "Build / Dist"
runs-on: ubuntu-latest
container:
image: ghcr.io/matrixai/github-runner
needs: [check-lint, check-test]
if: github.ref == 'refs/heads/staging'
steps:
- uses: actions/checkout@v4
- run: |
nix develop .#ci --command bash -c $'
npm run build --ignore-scripts --verbose
'
- uses: actions/upload-artifact@v4
with:
name: dist
path: ./dist

build-platforms:
name: "Build / Platforms"
runs-on: ${{ matrix.os }}
container:
image: ${{ matrix.platform == 'linux' && 'ghcr.io/matrixai/github-runner' || null }}
needs: build-dist
if: github.ref == 'refs/heads/staging'
strategy:
fail-fast: false
matrix:
include:
- platform: linux
os: ubuntu-latest
env:
npm_config_arch: "x64"
script: |
nix develop .#ci --command bash -c $'
npm run prebuild --verbose
npm test -- --ci --coverage
'
- platform: windows
os: windows-latest
env:
npm_config_devdir: "${{ github.workspace }}/tmp/node-gyp"
npm_config_arch: "x64"
script: |
mkdir -Force "$GITHUB_WORKSPACE/tmp"
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
./scripts/choco-install.ps1
refreshenv
npm install --ignore-scripts
$env:Path = "$(npm root)\.bin;" + $env:Path
npm test -- --ci --coverage
- platform: macos
os: macos-latest
env:
npm_config_devdir: "${{ github.workspace }}/tmp/node-gyp"
script: |
eval "$(brew shellenv)"
./scripts/brew-install.sh
hash -r
npm install --ignore-scripts
export PATH="$(npm root)/.bin:$PATH"
npm test -- --ci --coverage
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- uses: actions/download-artifact@v4
with:
name: dist
path: ./dist
- name: Build
env: ${{ matrix.env }}
run: ${{ matrix.script }}
- uses: actions/upload-artifact@v4
with:
name: builds-${{ matrix.platform }}
path: ./builds

build-prerelease:
name: "Build / Pre-release"
runs-on: ubuntu-latest
container:
image: ghcr.io/matrixai/github-runner
concurrency:
group: build-prerelease
cancel-in-progress: false
needs: [check-lint, check-test]
if: >
github.ref == 'refs/heads/staging' &&
startsWith(github.ref, 'refs/tags/v') &&
contains(github.ref, '-')
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
pattern: builds*
path: builds
merge-multiple: true
- name: Run pre-release
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
echo 'Publishing library prerelease'
nix develop .#ci --command bash -c $'
npm publish --tag prerelease --access public
'
for d in prebuild/*; do
tar \
--create \
--verbose \
--file="prebuild/$(basename $d).tar" \
--directory=prebuild \
"$(basename $d)"
done
nix develop .#ci --command bash -c $'
gh release \
create "$GITHUB_REF_NAME" \
prebuild/*.tar \
--title "$GITHUB_REF_NAME-$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
--notes "" \
--prerelease \
--target staging \
--repo "$GITHUB_REPOSITORY"
'
rm -f ./.npmrc

integration-merge:
name: "Integration / Merge"
runs-on: ubuntu-latest
concurrency:
group: integration-merge
cancel-in-progress: true
needs: [build-pull, build-platforms]
if: github.ref == 'refs/heads/staging'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GH_TOKEN }}
- name: Merge into master
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }}
GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }}
GIT_COMMITTER_EMAIL: ${{ secrets.GIT_COMMITTER_EMAIL }}
GIT_COMMITTER_NAME: ${{ secrets.GIT_COMMITTER_NAME }}
run: |
printf "Pipeline Succeeded on $GITHUB_RUN_ID for $GITHUB_SHA\n\n$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" \
| gh pr comment staging \
--body-file - \
--repo "$GITHUB_REPOSITORY"
git checkout master
git merge --ff-only "$GITHUB_SHA"
git push origin master

release-distribution:
name: "Release / Distribution"
runs-on: ubuntu-latest
container:
image: ghcr.io/matrixai/github-runner
concurrency:
group: release-distribution
cancel-in-progress: false
needs: integration-merge
if: >
github.ref == 'refs/heads/staging' &&
startsWith(github.ref, 'refs/tags/v') &&
!contains(github.ref, '-')
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
pattern: builds*
path: builds
merge-multiple: true
- name: Run release
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ./.npmrc
echo 'Publishing library'
nix develop .#ci --command bash -c $'
npm publish --access public
'
for d in prebuild/*; do
tar \
--create \
--verbose \
--file="prebuild/$(basename $d).tar" \
--directory=prebuild \
"$(basename $d)"
done
nix develop .#ci --command bash -c $'
gh release \
create "$GITHUB_REF_NAME" \
prebuild/*.tar \
--title "$GITHUB_REF_NAME-$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \
--notes "" \
--target master \
--repo "$GITHUB_REPOSITORY"
'
rm -f ./.npmrc
23 changes: 0 additions & 23 deletions .github/workflows/codesee-arch-diagram.yml

This file was deleted.

5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# js-mdns

staging:[![pipeline status](https://gitlab.com/MatrixAI/open-source/js-mdns/badges/staging/pipeline.svg)](https://gitlab.com/MatrixAI/open-source/js-mdns/commits/staging)
master:[![pipeline status](https://gitlab.com/MatrixAI/open-source/js-mdns/badges/master/pipeline.svg)](https://gitlab.com/MatrixAI/open-source/js-mdns/commits/master)

## Installation

```sh
@@ -11,7 +8,7 @@ npm install --save @matrixai/mdns

## Development

Run `nix-shell`, and once you're inside, you can use:
Run `nix develop`, and once you're inside, you can use:

```sh
# install (or reinstall packages from package.json)
Loading