This commit is contained in:
Joseph Garrone 2020-05-14 00:47:15 +02:00
parent 224dc389eb
commit a55f9e86eb
14 changed files with 449 additions and 2 deletions

75
.github/workflows/ci.yaml vendored Normal file
View file

@ -0,0 +1,75 @@
name: ci
on:
push:
branches:
- dev
pull_request:
branches:
- dev
jobs:
test_node:
runs-on: ubuntu-latest
if: ${{ !github.event.created }}
strategy:
matrix:
node: [ '13', '12', '11', '10', '8' ]
name: Test with Node v${{ matrix.node }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: npm install
- run: npm run build
- run: npm run test:node
trigger_publish:
name: Trigger publish.yaml workflow if package.json version updated ( and secrets.PAT is set ).
runs-on: ubuntu-latest
env:
PAT: ${{secrets.PAT}}
if: github.event_name == 'push' && github.event.head_commit.author.name != 'denoify_ci'
needs: test_node
steps:
- name: Get version on branch 'latest'
id: v_latest
uses: garronej/github_actions_toolkit@master
with:
action_name: get_package_json_version
owner: ${{github.repository_owner}}
repo: ${{github.event.repository.name}}
branch: latest
- name: Get version on master
id: v_master
uses: garronej/github_actions_toolkit@master
with:
action_name: get_package_json_version
owner: ${{github.repository_owner}}
repo: ${{github.event.repository.name}}
branch: ${{ github.sha }}
- name: 'Trigger the ''publish'' workflow'
if: ${{ !!env.PAT && steps.v_latest.outputs.version != steps.v_master.outputs.version && steps.v_master.outputs.version != '0.0.0' }}
uses: garronej/github_actions_toolkit@master
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
with:
action_name: dispatch_event
owner: ${{github.repository_owner}}
repo: ${{github.event.repository.name}}
event_type: publish
client_payload_json: |
${{
format(
'{{"from_version":"{0}","to_version":"{1}","repo":"{2}"}}',
steps.v_latest.outputs.version,
steps.v_master.outputs.version,
github.event.repository.name
)
}}

85
.github/workflows/publish.yaml vendored Normal file
View file

@ -0,0 +1,85 @@
on:
repository_dispatch:
types: publish
jobs:
update_changelog_and_sync_package_lock_version:
name: Update CHANGELOG.md and make sure package.json and package-lock.json versions matches.
runs-on: ubuntu-latest
steps:
- name: Synchronize package.json and package-lock.json version if needed.
uses: garronej/github_actions_toolkit@master
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
with:
action_name: sync_package_and_package_lock_version
owner: ${{github.repository_owner}}
repo: ${{github.event.client_payload.repo}}
branch: master
commit_author_email: ts_ci@github.com
- name: Update CHANGELOG.md
if: ${{ !!github.event.client_payload.from_version }}
uses: garronej/github_actions_toolkit@master
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
with:
action_name: update_changelog
owner: ${{github.repository_owner}}
repo: ${{github.event.client_payload.repo}}
branch_behind: latest
branch_ahead: master
commit_author_email: ts_ci@github.com
exclude_commit_from_author_names_json: '["ts_ci"]'
publish_npm:
runs-on: ubuntu-latest
needs: update_changelog_and_sync_package_lock_version
steps:
- name: Remove branch 'latest'
continue-on-error: true
run: git push origin :latest
- name: Create the new 'latest' branch
run: |
git branch latest
git checkout latest
git push origin latest
- uses: actions/setup-node@v1
- run: npm install
- run: npm run enable_short_import_path:npm
env:
DRY_RUN: "0"
- name: (DEBUG) Show how the files have been moved to enable short import
run: ls -lR
- name: Publishing on NPM
run: |
if [ "$NODE_AUTH_TOKEN" = "" ]; then
echo "Can't publish on NPM, You must first create a secret called NODE_AUTH_TOKEN that contains your NPM auth token. https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets"
false
fi
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
- name: Commit changes
run: |
git config --local user.email "ts_ci@github.com"
git config --local user.name "ts_ci"
git add -A
git commit -am "Automatic structural changes"
- name: Push changes
uses: ad-m/github-push-action@v0.5.0
with:
github_token: ${{ secrets.PAT }}
branch: latest
- name: Create Release
uses: garronej/create-release@master
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
with:
tag_name: ${{ github.event.client_payload.to_version }}
release_name: Release ${{ github.event.client_payload.to_version }}
branch: latest
draft: false
prerelease: false

View file

@ -0,0 +1,57 @@
on: create
jobs:
template_initialization:
runs-on: ubuntu-latest
steps:
- name: Checking availability for module name ${{github.event.repository.name}} on NPM.
id: id1
uses: garronej/github_actions_toolkit@master
with:
action_name: is_well_formed_and_available_module_name
module_name: ${{github.event.repository.name}}
- name: Checks results
run: |
if [ "$IS_VALID_NODE_MODULE_NAME" = "false" ]; then
echo $MODULE_NAME" is not a valid node module name"
false
fi
if [ "$IS_AVAILABLE_ON_NPM" = "false" ]; then
echo "WARNING: There is already a NPM module named "$MODULE_NAME", if you are not the owner consider picking another name"
fi
true
env:
MODULE_NAME: ${{github.event.repository.name}}
IS_VALID_NODE_MODULE_NAME: ${{steps.id1.outputs.is_valid_node_module_name}}
IS_AVAILABLE_ON_NPM: ${{steps.id1.outputs.is_available_on_npm}}
- uses: actions/checkout@v2
- name: Replace tokens in README.MD and package.json
uses: cschleiden/replace-tokens@v1
with:
files: '["README.md","package.json"]'
env:
REPO_NAME: ${{ github.event.repository.name }}
USER_OR_ORG: ${{ github.repository_owner }}
DESC: ${{ github.event.repository.description }}
- uses: actions/setup-node@v1
- name: Update pre-configured dev dependencies
run: |
npm install --save-dev denoify
npm install --save-dev typescript
npm install --save-dev evt
rm package-lock.json
- name: Remove this workflow, it only needs to be run once.
run: rm .github/workflows/template_initialization.yaml
- name: Commit files
run: |
git config --local user.email "ts_ci@github.com"
git config --local user.name "ts_ci"
git commit -am "Replacing the template's placeholders"
- name: Push changes
uses: ad-m/github-push-action@v0.5.0
with:
github_token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
branch: dev