Skip to content

main

main #9

Workflow file for this run

name: main
on:
push:
branches:
- main
schedule:
- cron: "0 0/4 * * *"
jobs:
# Check for Mediasoup version update
check:
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.check.outputs.new_version }}
steps:
# Checkout
- uses: actions/checkout@v4
# Check for Mediasoup version update
- name: Check for Mediasoup version update
id: check
run: |
function getLatestVersion() {
curl -s "https://registry.npmjs.com/mediasoup" | jq -r '.["dist-tags"].latest'
}
pkgJsonVersion=$(jq -r '.version' ./package.json)
latestVersion=$(getLatestVersion)
if [[ "$latestVersion" < "$pkgJsonVersion" ]]; then
echo "Published mediasoup version ${latestVersion} is older than version ${pkgJsonVersion} from the package.json file. Maybe there's a mistake in the package.json version?" >&2
exit 1
fi
if [[ "$latestVersion" == "$pkgJsonVersion" ]]; then
echo "Mediasoup version ${pkgJsonVersion} at package.json file is equal to latest published one." >&2
exit
fi
echo "old version: $pkgJsonVersion"
echo "new version: ${latestVersion}"
echo "new_version=${latestVersion}" >> "$GITHUB_OUTPUT"
# Update version and dependencies
update:
needs: check
if: ${{ needs.check.outputs.new_version != '' }}
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.update.outputs.new_version }}
steps:
- uses: actions/checkout@v4
# Setup Node.js
- name: Node.js
uses: actions/setup-node@v4
with:
cache: 'npm'
node-version: lts/-1
# Install dependencies
- run: npm ci --verbose
# Update flatbuffers
- name: Update flatbuffers
id: update
run: |
echo "old version: `node -p \"require('./package.json').version\"`"
new_version=`scripts/update.js`
echo "new version: ${new_version}"
echo "new_version=${new_version}" >> "$GITHUB_OUTPUT"
# Update
- name: Update package version
if : ${{ steps.update.outputs.new_version != '' }}
run: |
tmpfile=$(mktemp)
cp package.json "$tmpfile" &&
jq \
--arg version "${{ steps.update.outputs.new_version }}" \
'.version |= $version' \
"$tmpfile" \
> package.json &&
rm -f "$tmpfile"
- name: Update dependencies
if : ${{ steps.update.outputs.new_version != '' }}
run: |
# TODO: update dependencies from package.json
npx npm-check-updates --target semver --upgrade
- name: Install updated dependencies
if : ${{ steps.update.outputs.new_version != '' }}
run: npm install --verbose
# Ensure extracted tests are working
- name: Run tests
if : ${{ steps.update.outputs.new_version != '' }}
run: npm test
# Commit and push changes
- name: Commit and push changes
if : ${{ steps.update.outputs.new_version != '' }}
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git add .
git commit -m "chore(deps): update to mediasoup@${{ steps.update.outputs.new_version }}"
git tag "${{ steps.update.outputs.new_version }}"
git push
git push --tags
#
# Publish to registries and GitHub release
#
# GitHub Package Registry
publish-gpr:
needs: update
if: ${{ needs.update.outputs.new_version != '' }}
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
packages: write
steps:
# Checkout
- uses: actions/checkout@v4
with:
ref: ${{ needs.update.outputs.new_version }}
# Setup Node.js
- uses: actions/setup-node@v4
with:
cache: 'npm'
node-version: lts/-2
registry-url: https://npm.pkg.github.com/
# Publish
- run: npm ci --verbose
- run: npm publish --provenance
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
# NPM registry
publish-npm-registry:
needs: update
if: ${{ needs.update.outputs.new_version != '' }}
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.update.outputs.new_version }}
- uses: actions/setup-node@v4
with:
cache: 'npm'
node-version: lts/-2
registry-url: https://registry.npmjs.org/
# Publish
- run: npm ci --verbose
- run: npm publish --provenance
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
# GitHub release
upload-to-github-release:
needs: update
if: ${{ needs.update.outputs.new_version != '' }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.update.outputs.new_version }}
# Setup Node.js
- uses: actions/setup-node@v4
with:
cache: 'npm'
node-version: lts/-2
# Create package
- run: npm ci --verbose
- run: npm pack
# Create release
- name: Create release
uses: softprops/action-gh-release@v1
with:
files: '*.tgz'
generate_release_notes: true
tag_name: ${{ needs.update.outputs.new_version }}
# --verify-tag