Skip to content

Tutorial update - angular app no routing #286

Tutorial update - angular app no routing

Tutorial update - angular app no routing #286

# Should run Main Release Package on pull request [opened, synchronize, reopened, labeled, unlabeled, review_requested]
# only if head branch is named release-...
name: Package Main Release
on:
pull_request:
# https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#pull_request
types: [opened, synchronize, reopened, labeled, unlabeled]
branches:
- main
jobs:
# check if the incoming branch follows the naming conventions, otherwise skip the workflow because this is not a release PR!!!
checkHeadBranch:
runs-on: ubuntu-latest
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
# check head (source) branch
if: ${{ startsWith(github.head_ref, 'release-') }}
steps:
- run: echo "Run the jobs for the release pull_request"
# get the tag to release from the PR title
checkTitelTag:
runs-on: ubuntu-latest
needs: checkHeadBranch
steps:
# - uses: actions/checkout@v4
# needs uses: actions/checkout@ if script/module is required
- name: checkTitelTag
uses: actions/github-script@v6
id: get-tag
with:
result-encoding: string
script: |
if (context.payload.pull_request && context.payload.pull_request.title) {
const title = context.payload.pull_request.title;
const parts = title.split('release-');
if (parts.length === 2) {
const versionTag = parts[1];
core.info(`title contains version ${versionTag}`);
if(versionTag.startsWith('v')){
return versionTag;
}else{
core.setFailed(`Your PR title does not follow the naming convention of the version with "release-v..." ${title}`)
}
} else {
core.setFailed(`Your PR title does not follow the naming convention "release-v[0-9]+.[0-9]+.[0-9]" ${title}`)
}
}else{
core.setFailed(`context.payload does not have a pull_request" ${context.payload}`)
}
- name: log output
run: echo "${{ steps.get-tag.outputs.result }}"
outputs:
VERSION_TAG: ${{ steps.get-tag.outputs.result }}
# check if the tag is already published - uses @dlr-eoc/core-ui for test
checkTagOnNpm:
runs-on: ubuntu-latest
needs: checkTitelTag
if: ${{ needs.checkTitelTag.outputs.VERSION_TAG != '' }}
steps:
- uses: actions/checkout@v4
- name: checkout tag
run: |
git fetch --all --tags
git checkout ${{ needs.checkTitelTag.outputs.VERSION_TAG }}
- uses: actions/setup-node@v4
with:
node-version: 20.15.1
- run: rm -f .npmrc
- uses: ./.github/actions/check-tag-on-npm
with:
npmPackageName: "@dlr-eoc/core-ui"
tag: ${{ needs.checkTitelTag.outputs.VERSION_TAG }}
# check out the tag, build packages and store them as artifacts
build:
needs: [checkHeadBranch, checkTitelTag, checkTagOnNpm]
runs-on: ubuntu-latest
if: ${{ needs.checkTitelTag.outputs.VERSION_TAG != '' }}
steps:
- uses: actions/checkout@v4
- name: checkout tag
run: |
git fetch --all --tags
git checkout ${{ needs.checkTitelTag.outputs.VERSION_TAG }}
- uses: actions/setup-node@v4
with:
node-version: 20.15.1
- name: build
run: |
npm ci
npm run build
- name: Archive dist artifacts
uses: actions/upload-artifact@v3
with:
name: "dist"
path: dist
# if build works fine we can proceed, add a label and create the release
checkLabel:
runs-on: ubuntu-latest
needs: build
steps:
- name: checkLabel
uses: actions/github-script@v6
with:
script: |
if(context.payload.pull_request.labels){
const hasLabel = context.payload.pull_request.labels.find(i => i.name === 'RELEASE');
if(!hasLabel){
core.setFailed(`pull_request hasLabel 'RELEASE' === ${hasLabel}`)
}
}else{
core.setFailed(`context.payload does not have a pull_request" ${context.payload}`);
}
# check out the tag and create GH release with tag_name (https://github.com/softprops/action-gh-release)
gh-release:
needs: [checkHeadBranch, checkTitelTag, checkTagOnNpm, build, checkLabel]
if: ${{ needs.checkTitelTag.outputs.VERSION_TAG != '' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: checkout tag
run: |
git fetch --all --tags
git checkout ${{ needs.checkTitelTag.outputs.VERSION_TAG }}
- name: Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.checkTitelTag.outputs.VERSION_TAG }}
# download artifacts and publish packages
publish-gpr:
needs: [checkHeadBranch, checkTitelTag, checkTagOnNpm, build, checkLabel, gh-release]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download dist result from job build
uses: actions/download-artifact@v3
with:
name: "dist"
path: dist
- uses: actions/setup-node@v4
with:
node-version: 20.15.1
registry-url: https://npm.pkg.github.com/
scope: "@dlr-eoc"
- run: npm ci
### update npm to >8.19 for publish https://github.com/npm/cli/issues/2453 https://github.com/npm/cli/issues/3573
- run: npm i -g [email protected]
- run: rm -f .npmrc
### for each module in dist update package.json and create .npmrc
- run: node scripts/library/index.js --update-package=https://npm.pkg.github.com/
### for each module in dist publish frontend-libraries to registry
- run: |
for dir in ./dist/*/
do
dir=${dir%*/}
npm publish "$dir"
done
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
publish-npm:
needs: [checkHeadBranch, checkTitelTag, checkTagOnNpm, build, checkLabel, gh-release]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download dist result from job build
uses: actions/download-artifact@v3
with:
name: "dist"
path: dist
- uses: actions/setup-node@v4
with:
node-version: 20.15.1
registry-url: https://registry.npmjs.org/
scope: "@dlr-eoc"
- run: npm ci
### update npm to >8.19 for publish https://github.com/npm/cli/issues/2453 https://github.com/npm/cli/issues/3573
- run: npm i -g [email protected]
- run: rm -f .npmrc
### for each module in dist update package.json and create .npmrc
- run: node scripts/library/index.js --update-package=https://registry.npmjs.org/
### for each module in dist publish frontend-libraries to registry
- run: |
for dir in ./dist/*/
do
dir=${dir%*/}
npm publish "$dir" --access public
done
env:
NODE_AUTH_TOKEN: ${{secrets.PUBLISH_NPM_TOKEN}}