-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from indexdata/DEVOPS-946-workflows-npm
DEVOPS-946 workflows: Initial release-npm
- Loading branch information
Showing
1 changed file
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
name: release-npm | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v[0-9]+.[0-9]+.[0-9]+' # i.e. release tag only | ||
|
||
env: | ||
NODEJS_VERSION: '16' | ||
FOLIO_NPM_REGISTRY: 'https://repository.folio.org/repository/npm-folioci/' | ||
FOLIO_MD_REGISTRY: 'https://registry.folio-dev.indexdata.com' | ||
OKAPI_PULL_FOLIO: '{ "urls" : [ "https://folio-registry.dev.folio.org" ] }' | ||
OKAPI_PULL_INDEXDATA: '{ "urls" : [ "https://registry.folio-dev.indexdata.com" ] }' | ||
COMPILE_TRANSLATION_FILES: 'true' | ||
|
||
jobs: | ||
release-npm: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- name: Set TAG_VERSION | ||
run: echo "TAG_VERSION=$(echo ${GITHUB_REF#refs/tags/v})" >> $GITHUB_ENV | ||
- name: Get version from package.json | ||
id: package_version | ||
uses: notiz-dev/github-action-json-property@release | ||
with: | ||
path: 'package.json' | ||
prop_path: 'version' | ||
- name: Gather some variables | ||
run: | | ||
echo "PACKAGE_VERSION=${{ steps.package_version.outputs.prop }}" >> $GITHUB_ENV | ||
echo "DEFAULT_BRANCH=${{ github.event.repository.default_branch }}" >> $GITHUB_ENV | ||
- name: Report some variables | ||
run: | | ||
echo "PACKAGE_VERSION=${{ env.PACKAGE_VERSION }}" | ||
echo "TAG_VERSION=${{ env.TAG_VERSION }}" | ||
echo "github.REF=${{ github.REF }}" | ||
echo "DEFAULT_BRANCH=${{ env.DEFAULT_BRANCH }}" | ||
- name: Ensure that git tag matches the version from package.json | ||
if: ${{ env.TAG_VERSION != env.PACKAGE_VERSION }} | ||
run: | | ||
echo "Git tag version '${{ env.TAG_VERSION }}' does not match package.json version '${{ env.PACKAGE_VERSION }}'." | ||
exit 1 | ||
- name: Setup kernel for react native, increase watchers | ||
run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p | ||
- name: Setup NPM for install | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ env.NODEJS_VERSION }} | ||
check-latest: true | ||
always-auth: true | ||
- name: Set yarn config | ||
run: yarn config set @folio:registry $FOLIO_NPM_REGISTRY | ||
- name: Run yarn install | ||
run: yarn install --ignore-scripts | ||
- name: Run yarn list of modules | ||
run: yarn list --pattern "@folio|@reshare|@indexdata" | ||
- name: Run yarn lint | ||
run: yarn lint | ||
continue-on-error: true | ||
- name: Run yarn formatjs-compile | ||
if: ${{ env.COMPILE_TRANSLATION_FILES == 'true' }} | ||
run: yarn formatjs-compile | ||
- name: Generate FOLIO module descriptor | ||
run: yarn build-mod-descriptor | ||
- name: Print FOLIO module descriptor | ||
run: cat module-descriptor.json | ||
- name: Read module descriptor | ||
id: moduleDescriptor | ||
uses: juliangruber/read-file-action@v1 | ||
with: | ||
path: ./module-descriptor.json | ||
- name: Login ModuleDescriptor registry | ||
id: login-md-registry | ||
uses: indiesdev/[email protected] | ||
with: | ||
url: "${{ env.FOLIO_MD_REGISTRY }}/authn/login" | ||
method: "POST" | ||
accept: 201 | ||
headers: | | ||
{ | ||
"content-type": "application/json", | ||
"x-okapi-tenant": "${{ secrets.FOLIO_REGISTRY_TENANT }}" | ||
} | ||
body: | | ||
{ | ||
"username": "${{ secrets.FOLIO_REGISTRY_USERNAME }}", | ||
"password": "${{ secrets.FOLIO_REGISTRY_PASSWORD }}" | ||
} | ||
- name: Get the MD registry login token | ||
run: | | ||
echo "TOKEN_MD_REGISTRY=${{ fromJSON(steps.login-md-registry.outputs.response).headers['x-okapi-token'] }}" >> $GITHUB_ENV | ||
- name: Docker registry login | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKER_USER }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
- name: Start a local instance of Okapi | ||
run: | | ||
docker pull folioorg/okapi:latest | ||
docker run --name okapi -t -detach folioorg/okapi:latest dev | ||
echo "OKAPI_IP=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' okapi)" >> $GITHUB_ENV | ||
sleep 10 | ||
- name: Docker registry logout | ||
run: docker logout https://docker.io/v2/ | ||
- name: Pull FOLIO ModuleDescriptors to local Okapi | ||
uses: indiesdev/[email protected] | ||
with: | ||
url: "http://${{ env.OKAPI_IP }}:9130/_/proxy/pull/modules" | ||
method: "POST" | ||
accept: 200 | ||
timeout: 60000 | ||
headers: | | ||
{ | ||
"content-type": "application/json; charset=utf-8", | ||
"accept": "application/json; charset=utf-8" | ||
} | ||
body: ${{ env.OKAPI_PULL_FOLIO }} | ||
- name: Pull Index Data ModuleDescriptors to local Okapi | ||
uses: indiesdev/[email protected] | ||
with: | ||
url: "http://${{ env.OKAPI_IP }}:9130/_/proxy/pull/modules" | ||
method: "POST" | ||
accept: 200 | ||
timeout: 60000 | ||
headers: | | ||
{ | ||
"content-type": "application/json; charset=utf-8", | ||
"accept": "application/json; charset=utf-8" | ||
} | ||
body: ${{ env.OKAPI_PULL_INDEXDATA }} | ||
- name: Perform local Okapi dependency check | ||
uses: indiesdev/[email protected] | ||
with: | ||
url: "http://${{ env.OKAPI_IP }}:9130/_/proxy/modules?preRelease=false&npmSnapshot=false" | ||
method: "POST" | ||
accept: 201 | ||
timeout: 60000 | ||
headers: | | ||
{ | ||
"content-type": "application/json; charset=utf-8", | ||
"accept": "application/json; charset=utf-8" | ||
} | ||
body: ${{ steps.moduleDescriptor.outputs.content }} | ||
- name: Setup NPM for publish | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ env.NODEJS_VERSION }} | ||
check-latest: true | ||
always-auth: true | ||
registry-url: "https://registry.npmjs.org" | ||
- name: Exclude some CI-generated artifacts in package | ||
run: | | ||
echo ".github" >> .npmignore | ||
echo "artifacts" >> .npmignore | ||
- name: Publish NPM to npmjs registry | ||
run: npm publish --access=public | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_NPMJS }} | ||
- name: Publish ModuleDescriptor to MD registry | ||
id: result-md-registry | ||
uses: indiesdev/[email protected] | ||
with: | ||
url: "${{ env.FOLIO_MD_REGISTRY }}/_/proxy/modules" | ||
method: "POST" | ||
accept: 201 | ||
headers: | | ||
{ | ||
"content-type": "application/json", | ||
"x-okapi-tenant": "${{ secrets.FOLIO_REGISTRY_TENANT }}", | ||
"x-okapi-token": "${{ env.TOKEN_MD_REGISTRY }}" | ||
} | ||
body: ${{ steps.moduleDescriptor.outputs.content }} | ||
- name: Publish yarn.lock | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: yarn.lock | ||
path: yarn.lock | ||
retention-days: 5 |