-
Notifications
You must be signed in to change notification settings - Fork 1
159 lines (141 loc) · 5.45 KB
/
release.yaml
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: Release Packages Workflow
on:
push:
branches:
- main
env:
HUSKY: 0
PROJECT_NAME: main
REPOSITORY: jamilomar
jobs:
packaging:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ github.workspace }}
strategy:
matrix:
node-version: [18]
npm-version: [8]
steps:
- uses: pnpm/[email protected]
with:
version: 9.7.0
- uses: actions/[email protected]
with:
fetch-depth: 0
- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/[email protected]
with:
main-branch-name: main
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/[email protected]
with:
node-version: ${{ matrix.node-version }}
always-auth: true
registry-url: https://registry.npmjs.org
- name: Print node/pnpm versions
id: versions
run: |
node_ver=$( node --version )
pnpm_ver=$( pnpm --version || true )
echo "Node: ${node_ver:1}"
echo "PNPM: $pnpm_ver"
echo "node_version=${node_ver:1}" >>$GITHUB_OUTPUT
- name: Use the node_modules cache if available [pnpm]
uses: actions/[email protected]
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-node-${{ steps.versions.outputs.node_version }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-node-${{ steps.versions.outputs.node_version }}-
- name: Install dependencies
run: |
echo "Running pnpm install"
pnpm install --frozen-lockfile
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build Project
run: |
pnpm nx run-many --target=build --all --parallel 4
- name: Modify Workspace File
run: sed -e "s|'libs\/|'dist/|" pnpm-workspace.yaml > pnpm-new.yaml && mv pnpm-new.yaml pnpm-workspace.yaml
- name: Create and Publish versions
id: changesets
uses: changesets/[email protected]
with:
commit: 'chore: update versions'
title: 'chore: update versions'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Release Changesets
id: release-changesets
if: steps.changesets.outputs.hasChangesets == 'false'
run: |
pnpm release:ci
echo "Modify Workspace File Back"
sed -e "s|'dist\/|'libs/|" pnpm-workspace.yaml > pnpm-new.yaml && mv pnpm-new.yaml pnpm-workspace.yaml
echo mainApiVersion="" >>$GITHUB_OUTPUT
echo mainAppVersion="" >>$GITHUB_OUTPUT
pnpm set-versions
if [ -f MAIN_API_VERSION ]; then
echo "mainApiVersion=$(cat MAIN_API_VERSION)" >>$GITHUB_OUTPUT
rm MAIN_API_VERSION
else
echo mainApiVersion="" >>$GITHUB_OUTPUT
fi
if [ -f MAIN_APP_VERSION ]; then
echo "mainAppVersion=$(cat MAIN_APP_VERSION)" >>$GITHUB_OUTPUT
rm MAIN_APP_VERSION
else
echo mainAppVersion="" >>$GITHUB_OUTPUT
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
outputs:
mainApiVersion: ${{ steps.release-changesets.outputs.mainApiVersion }}
mainAppVersion: ${{ steps.release-changesets.outputs.mainAppVersion }}
publish-artifacts-for-api:
needs: [packaging]
if: needs.packaging.outputs.mainApiVersion != ''
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ github.workspace }}
steps:
- name: Set Docker Login to ghcr.io
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- uses: actions/[email protected]
with:
fetch-depth: 0
- name: Publish Artifacts for Api
run: |
echo "Using version: ${{ needs.packaging.outputs.mainApiVersion }}"
docker build -t ghcr.io/${{ env.REPOSITORY }}/${{ env.PROJECT_NAME }}-api -t ghcr.io/${{ env.REPOSITORY }}/${{ env.PROJECT_NAME }}-api:${{ needs.packaging.outputs.mainApiVersion }} --build-arg GITHUB_TOKEN=${{ env.GITHUB_TOKEN }} -f ./apps/main/api/Dockerfile .
docker push ghcr.io/${{ env.REPOSITORY }}/${{ env.PROJECT_NAME }}-api --all-tags
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
outputs:
mainApiVersion: ${{ needs.packaging.outputs.mainApiVersion }}
publish-artifacts-for-app:
needs: [packaging]
if: needs.packaging.outputs.mainAppVersion != ''
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ github.workspace }}
steps:
- name: Set Docker Login to ghcr.io
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- uses: actions/[email protected]
with:
fetch-depth: 0
- name: Publish Artifacts for App
run: |
echo "Using version: ${{ needs.packaging.outputs.mainAppVersion }}"
docker build -t ghcr.io/${{ env.REPOSITORY }}/${{ env.PROJECT_NAME }}-app -t ghcr.io/${{ env.REPOSITORY }}/${{ env.PROJECT_NAME }}-app:${{ needs.packaging.outputs.mainAppVersion }} --build-arg GITHUB_TOKEN=${{ env.GITHUB_TOKEN }} -f ./apps/main/app/Dockerfile .
docker push ghcr.io/${{ env.REPOSITORY }}/${{ env.PROJECT_NAME }}-app --all-tags
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
outputs:
mainAppVersion: ${{ needs.packaging.outputs.mainAppVersion }}