generated from sinedied/devto-github-template
-
Notifications
You must be signed in to change notification settings - Fork 4
97 lines (95 loc) · 3.31 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
name: ci
on:
pull_request:
branches:
- main
jobs:
variables:
outputs:
author_github_user: ${{ steps.var.outputs.author_github_user}}
author_github_user_safe: ${{ steps.var.outputs.author_github_user_safe}}
runs-on: "ubuntu-latest"
steps:
- name: Setting global variables
uses: actions/github-script@v6
id: var
with:
script: |
core.setOutput('author_github_user', '${{ github.event.pull_request.user.login }}');
core.setOutput('author_github_user_safe', '${{ github.event.pull_request.user.login }}'.replaceAll('-', '_').trim());
changes:
runs-on: ubuntu-latest
needs: [variables]
env:
AUTHOR_GITHUB_USER: ${{ needs.variables.outputs.author_github_user }}
AUTHOR_GITHUB_USER_SAFE: ${{ needs.variables.outputs.author_github_user_safe }}
outputs:
theirs: ${{ steps.changes.outputs.theirs }}
others: ${{ steps.changes.outputs.others }}
steps:
- uses: dorny/paths-filter@v2
name: Checking changes for ${{ env.AUTHOR_GITHUB_USER }} (${{ env.AUTHOR_GITHUB_USER_SAFE }})
id: changes
with:
filters: |
theirs:
- 'posts/${{ env.AUTHOR_GITHUB_USER }}/**'
others:
- 'posts/!(${{ env.AUTHOR_GITHUB_USER }}/**)/**'
lint:
runs-on: ubuntu-latest
needs: [changes, variables]
if: needs.changes.outputs.theirs == 'true'
env:
AUTHOR_GITHUB_USER: ${{ needs.variables.outputs.author_github_user }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm ci
- run: npx --no-install markdownlint **/*.md
working-directory: posts/${{ env.AUTHOR_GITHUB_USER }}
scope:
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.others == 'true'
steps:
- name: Checking out of scope changes
uses: actions/github-script@v6
with:
script: |
core.setFailed("There are changes outside of the user's scope!")
dry-run:
runs-on: ubuntu-latest
needs: [changes,variables]
env:
AUTHOR_GITHUB_USER: ${{ needs.variables.outputs.author_github_user }}
AUTHOR_GITHUB_USER_SAFE: ${{ needs.variables.outputs.author_github_user_safe }}
outputs:
result_summary_table_json: ${{ steps.dry-run.outputs.result_summary_table_json }}
if: needs.changes.outputs.theirs == 'true'
steps:
- uses: actions/checkout@v3
- name: Dry-run on dev.to for ${{ env.AUTHOR_GITHUB_USER }} (${{ env.AUTHOR_GITHUB_USER_SAFE }})
id: dry-run
uses: cloudx-labs/publish-devto@main
with:
devto_key: ${{ secrets[format('devto_key_{0}', env.AUTHOR_GITHUB_USER_SAFE)] }}
github_token: ${{ secrets.CI_PAT_TOKEN }}
files: "posts/${{ env.AUTHOR_GITHUB_USER }}/**/*.md"
dry_run: true
branch: ${{ github.event.pull_request.head.ref }}
result-comment:
runs-on: ubuntu-latest
needs: dry-run
steps:
- name: Dry-run output comment
uses: KeisukeYamashita/create-comment@v1
with:
check-only-first-line: true
comment: |
Dry-run output:
```
${{ fromJSON(needs.dry-run.outputs.result_summary_table_json).content }}
```