Skip to content

Commit e0fa746

Browse files
authored
Merge pull request #12 from eduzz/hotfix-cpi-2344-prettier-tailwind
Hotfix cpi 2344 prettier tailwind
2 parents a425b66 + e59ca0e commit e0fa746

9 files changed

Lines changed: 249 additions & 114 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: 'npm-publish'
2+
description: 'npm-publish is a github composite action publish npm package.'
3+
inputs:
4+
github-token:
5+
description: 'Github Token'
6+
required: true
7+
default: ''
8+
version:
9+
description: 'Version to be published'
10+
required: true
11+
default: ''
12+
npm-auth-token:
13+
description: 'NPM auth token'
14+
required: true
15+
default: ''
16+
path:
17+
description: 'Path to the package'
18+
required: true
19+
default: ''
20+
runs:
21+
using: "composite"
22+
steps:
23+
- name: Node
24+
uses: actions/setup-node@v3
25+
- name: Print version
26+
shell: bash
27+
run: echo "New version ${{ inputs.version }}"
28+
- name: Download Build Artifact
29+
uses: actions/download-artifact@v4
30+
with:
31+
name: build-artifact
32+
- name: Setup NPM Registry
33+
shell: bash
34+
run: echo '//registry.npmjs.org/:_authToken=${{ inputs.npm-auth-token }}' > ~/.npmrc && npm config get registry && npm whoami
35+
- name: Publish
36+
shell: bash
37+
run: npm publish ${{ inputs.path }}

.github/workflows/publish.yml

Lines changed: 119 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,155 @@
1-
name: Publish
1+
name: Deploy
22

33
on:
44
push:
55
branches:
66
- master
7+
- feature-*
8+
- release-*
9+
- hotfix-*
710

811
concurrency:
912
group: publish-${{ github.ref }}
1013
cancel-in-progress: true
1114

1215
jobs:
16+
build:
17+
name: Build
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Clone
21+
uses: actions/checkout@v3
22+
- name: Node
23+
uses: actions/setup-node@v3
24+
- name: Cache
25+
id: cache-nodemodules
26+
uses: actions/cache@v3
27+
with:
28+
path: node_modules
29+
key: packages-${{ hashFiles('yarn.lock') }}
30+
restore-keys: |
31+
packages-
32+
- name: Install
33+
run: yarn install
34+
- name: Lint
35+
run: yarn lint
36+
- name: Build
37+
run: yarn build
38+
- name: Upload Build Artifact
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: build-artifact
42+
path: ./
43+
1344
should-release:
45+
needs: [build]
1446
name: Should Release
1547
runs-on: ubuntu-latest
1648
steps:
1749
- name: Clone
1850
uses: actions/checkout@v4
1951
- name: Node
20-
uses: actions/setup-node@v4
21-
with:
22-
node-version: 20
52+
uses: actions/setup-node@v3
2353
- name: Deps
2454
run: npm i -g semver
2555
- name: Run should-release
26-
run: node ./scripts/should-release.js
56+
shell: bash
57+
run: scripts/should-release.sh package.json
2758
- name: Current Version
2859
id: current-version
29-
run: echo 'CURRENT_VERSION='$(node -p -e "require('./package.json').version") >> $GITHUB_OUTPUT
60+
run: echo 'current_version='$(node -p -e "require('./package.json').version") >> $GITHUB_OUTPUT
3061
- name: Check Skip Release
3162
id: skip-release
32-
run: echo 'SKIP='$(cat .skip-release) >> $GITHUB_OUTPUT
63+
run: echo 'skip='$(cat .skip-release) >> $GITHUB_OUTPUT
3364
outputs:
34-
SKIP: ${{ steps.skip-release.outputs.SKIP }}
35-
CURRENT_VERSION: ${{ steps.current-version.outputs.CURRENT_VERSION }}
36-
37-
publish:
65+
skip: ${{ steps.skip-release.outputs.skip }}
66+
current_version: ${{ steps.current-version.outputs.current_version }}
67+
68+
release-candidate:
3869
needs: [should-release]
39-
if: needs.should-release.outputs.SKIP != 'true'
70+
if: github.ref != 'refs/heads/master' && (startsWith(github.ref, 'refs/heads/feature-') || startsWith(github.ref, 'refs/heads/hotfix-') || startsWith(github.ref, 'refs/heads/release-'))
71+
name: Release Candidate
72+
runs-on: ubuntu-latest
73+
steps:
74+
- uses: actions/checkout@v4
75+
- name: Download Build Artifact
76+
uses: actions/download-artifact@v4
77+
with:
78+
name: build-artifact
79+
path: ./
80+
- name: Update package.json with RC version
81+
if: ${{ needs.should-release.outputs.skip != 'true' }}
82+
run: scripts/rc.sh package.json
83+
- name: Upload Updated Artifact
84+
if: ${{ needs.should-release.outputs.skip != 'true' }}
85+
uses: actions/upload-artifact@v4
86+
with:
87+
name: build-artifact
88+
path: ./
89+
overwrite: true
90+
91+
publish:
92+
needs: [should-release, release-candidate]
93+
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/hotfix-') || startsWith(github.ref, 'refs/heads/release-')
4094
name: Publish
4195
runs-on: ubuntu-latest
96+
steps:
97+
- uses: actions/checkout@v4
98+
- id: npm-publish
99+
if: ${{ needs.should-release.outputs.skip != 'true' }}
100+
uses: ./.github/actions/npm-publish
101+
with:
102+
github-token: ${{ secrets.GITHUB_TOKEN }}
103+
version: ${{ needs.should-release.outputs.current_version }}
104+
npm-auth-token: ${{ secrets.NPM_AUTH_TOKEN }}
105+
path: .
106+
107+
create-tag:
108+
needs: [publish]
109+
if: github.ref == 'refs/heads/master'
110+
name: Create Tag
111+
runs-on: ubuntu-latest
42112
steps:
43113
- name: Clone
44114
uses: actions/checkout@v4
45-
- name: Node
46-
uses: actions/setup-node@v4
47115
with:
48-
node-version: 20
49-
- name: Cache Yarn
50-
id: cache-nodemodules
51-
uses: actions/cache@v4
116+
fetch-depth: 0
117+
- name: Semver
118+
id: semver
119+
uses: luanlmd/semver-composite-action@v1.0.0
52120
with:
53-
path: node_modules
54-
key: packages-${{ hashFiles('yarn.lock') }}
55-
restore-keys: |
56-
packages-
57-
- name: Yarn
58-
if: steps.cache-nodemodules.outputs.cache-hit != 'true'
59-
run: yarn install --immutable
60-
- name: Setup NPM Registry
61-
run: echo '//registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}' > ~/.npmrc && npm config get registry && npm whoami
62-
- name: Build
63-
run: npm run build
64-
- name: Publish
65-
run: npm publish
66-
- name: Check Skip Release
67-
id: skip-release
68-
run: echo 'SKIP='$(cat .skip-release) >> $GITHUB_OUTPUT
121+
repo-path: ${{ github.workspace }}
69122
- name: Create tag
70-
uses: actions/github-script@v7
123+
env:
124+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
125+
run: |
126+
git tag ${{ steps.semver.outputs.version }}
127+
git push --tags
128+
129+
notify:
130+
needs: [build, should-release, release-candidate, publish, create-tag]
131+
if: always()
132+
name: Notify
133+
runs-on: ubuntu-latest
134+
steps:
135+
- name: Discord Message on Success
136+
if: ${{ needs.build.result != 'failure' && needs.should-release.result != 'failure' && needs.publish.result != 'failure' && needs.create-tag.result != 'failure'}}
137+
uses: vitorvmrs/discord-send-embed@0f0cb61f7ed052734cc11765a5b2c5d0a5c3d9c2
71138
with:
72-
github-token: ${{ secrets.GITHUB_TOKEN }}
73-
script: |
74-
github.rest.git.createRef({
75-
owner: context.repo.owner,
76-
repo: context.repo.repo,
77-
ref: "refs/tags/v${{ needs.should-release.outputs.CURRENT_VERSION }}",
78-
sha: context.sha
79-
})
80-
outputs:
81-
SKIP: ${{ steps.skip-release.outputs.SKIP }}
139+
webhook-url: ${{ secrets.PI_DISCORD_WEBHOOK }}
140+
title: "${{ github.repository }}/${{ github.ref_name }}"
141+
url: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
142+
description: "🫡 DEPLOYED / Linterzinhiúu =]"
143+
color: 65280
144+
footer-text: "${{ github.sha }} - ${{ github.event.head_commit.message }}"
145+
- name: Discord Message on Failure
146+
if: ${{ needs.build.result == 'failure' || needs.should-release.result == 'failure' || needs.publish.result == 'failure' || needs.create-tag.result == 'failure' }}
147+
uses: vitorvmrs/discord-send-embed@0f0cb61f7ed052734cc11765a5b2c5d0a5c3d9c2
148+
with:
149+
webhook-url: ${{ secrets.PI_DISCORD_WEBHOOK }}
150+
title: "${{ github.repository }}/${{ github.ref_name }}"
151+
url: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
152+
description: "❌ FAILED / Deu ruim =["
153+
color: 16711680
154+
footer-text: "${{ github.sha }} - ${{ github.event.head_commit.message }}"
155+

.prettierrc.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1 @@
1-
module.exports = {
2-
singleQuote: true,
3-
jsxSingleQuote: true,
4-
quoteProps: 'consistent',
5-
trailingComma: 'none',
6-
useTabs: false,
7-
tabWidth: 2,
8-
bracketSpacing: true,
9-
bracketSameLine: false,
10-
arrowParens: 'avoid',
11-
endOfLine: 'auto',
12-
printWidth: 120,
13-
semi: true,
14-
plugins: ['prettier-plugin-tailwindcss'],
15-
tailwindFunctions: ['tw', 'clsx']
16-
};
1+
module.exports = require('./prettierrc');

ignores.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const parse = require('parse-gitignore');
55

66
module.exports = function gitignore(...extra) {
77
const files = globSync('./**/.gitignore');
8-
const ignores = [];
8+
const ignores = ['dist/**', 'build/**', '.turbo/**', 'node_modules/**'];
99

1010
for (const file of files) {
1111
let content = '';

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@eduzz/eslint-config",
33
"private": false,
4-
"version": "2.5.5",
4+
"version": "2.5.6",
55
"keywords": [
66
"eduzz",
77
"eslint"

prettierrc.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const path = require('path');
2+
3+
const config = {
4+
singleQuote: true,
5+
jsxSingleQuote: true,
6+
quoteProps: 'consistent',
7+
trailingComma: 'none',
8+
useTabs: false,
9+
tabWidth: 2,
10+
bracketSpacing: true,
11+
bracketSameLine: false,
12+
arrowParens: 'avoid',
13+
endOfLine: 'auto',
14+
printWidth: 120,
15+
semi: true,
16+
tailwindFunctions: ['tw', 'clsx']
17+
};
18+
19+
try {
20+
require.resolve('prettier-plugin-tailwindcss', {
21+
paths: [path.dirname(require.resolve('@eduzz/eslint-config/package.json'))]
22+
});
23+
24+
config.plugins = [
25+
require.resolve('prettier-plugin-tailwindcss', {
26+
paths: [path.dirname(require.resolve('@eduzz/eslint-config/package.json'))]
27+
})
28+
];
29+
} catch (error) {
30+
console.info('prettier-plugin-tailwindcss not found, Tailwind formatting disabled');
31+
}
32+
33+
module.exports = config;

scripts/rc.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
PACKAGE_JSON=$1
6+
7+
if [ -z "$PACKAGE_JSON" ]; then
8+
echo "Usage: $0 <package-json-path>"
9+
exit 1
10+
fi
11+
12+
VERSION=$(jq -r .version "$PACKAGE_JSON")
13+
PACKAGE_NAME=$(jq -r .name "$PACKAGE_JSON")
14+
BASE_VERSION=$(echo "$VERSION" | grep -o "^[0-9]\+\.[0-9]\+\.[0-9]\+")
15+
16+
RC_VERSION=$(npm view "$PACKAGE_NAME" versions --json | jq -r '.[]' | grep "${BASE_VERSION}-rc" | sort -V | tail -1 | awk -F'-rc.' '{print $1"-rc."($2+1)}')
17+
18+
if [ -z "$RC_VERSION" ]; then
19+
RC_VERSION="${VERSION}-rc.0"
20+
fi
21+
22+
jq --arg version "$RC_VERSION" '.version = $version' "$PACKAGE_JSON" > temp.json && mv temp.json "$PACKAGE_JSON"
23+
24+
echo "Updated version to: $RC_VERSION"

scripts/should-release.js

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)