|
| 1 | +name: Test Dingtalk Text |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - ci/dingtalk-text-workflow |
| 7 | + paths: |
| 8 | + - .github/workflows/test-dingtalk-text.yml |
| 9 | + - scripts/generate-dingtalk-text.js |
| 10 | + - CHANGELOG.md |
| 11 | + - package.json |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +jobs: |
| 15 | + test-dingtalk-text: |
| 16 | + name: Test Dingtalk Text |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: Checkout |
| 20 | + uses: actions/checkout@v3 |
| 21 | + - name: Setup Node |
| 22 | + uses: actions/setup-node@v3 |
| 23 | + with: |
| 24 | + node-version: '18' |
| 25 | + - name: Setup Environment |
| 26 | + id: setup_environment |
| 27 | + run: echo "package_version=$(node -p \"require('./package.json').version\")" >> $GITHUB_OUTPUT |
| 28 | + - name: Generate Changelog |
| 29 | + id: changelog |
| 30 | + uses: mindsers/changelog-reader-action@v2 |
| 31 | + with: |
| 32 | + version: ${{ steps.setup_environment.outputs.package_version }} |
| 33 | + path: ./CHANGELOG.md |
| 34 | + - name: Generate Dingtalk Text File |
| 35 | + env: |
| 36 | + PACKAGE_VERSION: ${{ steps.setup_environment.outputs.package_version }} |
| 37 | + CHANGELOG_CHANGES: ${{ steps.changelog.outputs.changes }} |
| 38 | + run: node ./scripts/generate-dingtalk-text.js > dingtalk-text.json |
| 39 | + - name: Validate Dingtalk Text |
| 40 | + env: |
| 41 | + PACKAGE_VERSION: ${{ steps.setup_environment.outputs.package_version }} |
| 42 | + run: | |
| 43 | + node <<'NODE' |
| 44 | + const fs = require('fs'); |
| 45 | + const raw = fs.readFileSync('dingtalk-text.json', 'utf8'); |
| 46 | + const text = JSON.parse(raw); |
| 47 | +
|
| 48 | + if (!text.includes(`TSwagger v${process.env.PACKAGE_VERSION} Published`)) { |
| 49 | + throw new Error('Missing release title'); |
| 50 | + } |
| 51 | +
|
| 52 | + if (!text.includes('Changes in this release:')) { |
| 53 | + throw new Error('Missing changelog heading'); |
| 54 | + } |
| 55 | +
|
| 56 | + if (!text.includes('VSCode Marketplace')) { |
| 57 | + throw new Error('Missing marketplace link text'); |
| 58 | + } |
| 59 | +
|
| 60 | + const summary = [ |
| 61 | + '## Generated DingTalk Text JSON', |
| 62 | + '', |
| 63 | + '```json', |
| 64 | + raw, |
| 65 | + '```', |
| 66 | + '', |
| 67 | + '## Decoded Markdown Preview', |
| 68 | + '', |
| 69 | + text, |
| 70 | + '' |
| 71 | + ].join('\n'); |
| 72 | +
|
| 73 | + fs.appendFileSync( |
| 74 | + process.env.GITHUB_STEP_SUMMARY, |
| 75 | + summary |
| 76 | + ); |
| 77 | + NODE |
0 commit comments