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

🏗 Automate bento publishing with a GitHub Action #34430

Merged
merged 8 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/publish-npm-packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Publish Bento Packages on NPM
on:
workflow_dispatch:
inputs:
ampversion:
description: 'AMP version'
required: true
tag:
description: 'NPM package tag (latest | nightly)'
required: true
jobs:
setup:
runs-on: ubuntu-latest
outputs:
extensions: ${{ steps.get-extensions.outputs.extensions }}
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.events.inputs.ampversion }}
- name: Get extensions to publish
id: get-extensions
run: |
EXTENSIONS=$(node ./build-system/npm-publish/get-extensions.js)
echo "::set-output name=extensions::{\"include\":${EXTENSIONS}}"
publish:
estherkim marked this conversation as resolved.
Show resolved Hide resolved
if: github.repository == 'ampproject/amphtml'
environment: NPM_TOKEN #TODO: change environment name in repo settings
needs: setup
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.setup.outputs.extensions) }}
fail-fast: false
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.events.inputs.ampversion }}
- uses: actions/setup-node@v2
with:
check-latest: true
registry-url: https://registry.npmjs.org
- name: Build package
run: |
npm install
node ./build-system/npm-publish/build-npm-binaries.js ${{ matrix.extension }}
node ./build-system/npm-publish/write-package-jsons.js ${{ matrix.extension }} ${{ github.event.inputs.ampversion }}
- name: Publish v1
run: npm publish ./extensions/${{ matrix.extension }}/1.0 --access public --tag ${{ github.event.inputs.tag }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could there ever be a time when an extension with a v2 will no longer have a regularly maintained v1? If so, maybe add the "if exists" check here as well for future proofing?

env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish v2 if it exists
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if the above comment makes sense, maybe remove "if it exists" from the job name for a cleaner look?

run: |
if $(test -d ${{ github.workspace }}/extensions/${{ matrix.extension }}/2.0); then
npm publish ./extensions/${{ matrix.extension }}/2.0 --access public --tag ${{ github.event.inputs.tag }}
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
*/

const [extension] = process.argv.slice(2);
const {timedExecOrDie} = require('../../../build-system/pr-check/utils');
const {updatePackages} = require('../../../build-system/common/update-packages');
const {timedExecOrDie} = require('../pr-check/utils');
const {updatePackages} = require('../common/update-packages');

updatePackages();
timedExecOrDie(`amp build --extensions=${extension} --core_runtime_only`);
Expand Down
27 changes: 27 additions & 0 deletions build-system/npm-publish/get-extensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright 2021 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @fileoverview
* Gets Bento components to publish.
*/

const bundles = require('../compile/bundles.config.extensions.json');
const extensions = bundles
.filter((bundle) => bundle.options?.npm)
.map((bundle) => ({'extension': bundle.name}));
console /*OK*/
.log(JSON.stringify(extensions));
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/

const [extension, ampVersion] = process.argv.slice(2);
const {log} = require('../../../build-system/common/logging');
const {log} = require('../common/logging');
const {stat, writeFile} = require('fs/promises');
const {valid} = require('semver');

Expand All @@ -38,7 +38,11 @@ async function writePackageJson(extensionVersion) {
const minor = ampVersion.slice(0, 10);
const patch = Number(ampVersion.slice(-3)); // npm trims leading zeroes in patch number, so mimic this in package.json
const version = `${major}.${minor}.${patch}`;
if (!valid(version) || ampVersion.length != 13 || extensionVersionArr[1] !== '0') {
if (
!valid(version) ||
ampVersion.length != 13 ||
extensionVersionArr[1] !== '0'
) {
log(
'Invalid semver version',
version,
Expand Down