|
| 1 | +name: Publish nightly to npm |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: "30 6 * * *" |
| 6 | + |
| 7 | +jobs: |
| 8 | + check_date: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + name: Check latest commit |
| 11 | + outputs: |
| 12 | + should_run: ${{ steps.should_run.outputs.should_run }} |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v2 |
| 15 | + - name: print latest_commit |
| 16 | + run: echo ${{ github.sha }} |
| 17 | + |
| 18 | + - id: should_run |
| 19 | + continue-on-error: true |
| 20 | + name: check latest commit is less than a day |
| 21 | + if: ${{ github.event_name == 'schedule' }} |
| 22 | + run: test -z $(git rev-list --after=24hours ${{ github.sha }}) && echo "::set-output name=should_run::false" |
| 23 | + |
| 24 | + publish: |
| 25 | + needs: check_date |
| 26 | + if: ${{ needs.check_date.outputs.should_run != 'false' }} |
| 27 | + runs-on: ubuntu-latest |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@v1 |
| 30 | + - uses: actions/setup-node@v1 |
| 31 | + with: |
| 32 | + node-version: "12.x" |
| 33 | + registry-url: https://registry.npmjs.org/ |
| 34 | + - run: npm ci |
| 35 | + - run: npm test |
| 36 | + |
| 37 | + - run: sudo apt install -y moreutils |
| 38 | + - run: jq '.name="nightly-esprima"' package.json | sponge package.json |
| 39 | + name: Edit package name |
| 40 | + - run: | |
| 41 | + jq --arg ver $(date +"%Y.%m.%d") '.version=$ver' package.json | sponge package.json |
| 42 | + sed -i '/export const version/d' src/esprima.ts |
| 43 | + echo "export const version = '$(date +'%Y.%m.%d')';" >> src/esprima.ts |
| 44 | + name: Edit package version |
| 45 | + - run: | |
| 46 | + sed -i '1,4d' README.md |
| 47 | + sed -i "s/require('esprima')/require('nightly-esprima')/" README.md |
| 48 | + name: Tweak README |
| 49 | + - run: git diff |
| 50 | + |
| 51 | + - run: npm publish --access public |
| 52 | + env: |
| 53 | + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} |
0 commit comments