Repository navigation
Expand file tree
/
Copy pathworkflow.yml
More file actions
110 lines (108 loc) · 3.57 KB
/
Copy pathworkflow.yml
File metadata and controls
110 lines (108 loc) · 3.57 KB
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
# Replace ORG and PROJECT
name: CI
on:
push:
branches:
- main
pull_request:
jobs:
test:
name: Test
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout the repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Install Node.js & pnpm
uses: pnpm/setup@84cb39b217b10273981911c288cd62326dc7c6d2 # v2.0.2
- name: Install dependencies
run: pnpm ci
- name: Run tests
run: pnpm test
build:
name: Build
runs-on: ubuntu-latest
permissions:
contents: read
if: github.ref == 'refs/heads/main'
needs:
- test
steps:
- name: Checkout the repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Install Node.js & pnpm
uses: pnpm/setup@84cb39b217b10273981911c288cd62326dc7c6d2 # v2.0.2
- name: Install dependencies
run: pnpm ci
- name: Install production dependencies
run: pnpm install --prod --ignore-scripts
- name: Build static files
run: pnpm build
- name: Pack build artifacts
run: tar -cf dist.tar dist
- name: Upload build artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: dist
path: dist.tar
retention-days: 1
deploy:
name: Deploy
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
if: github.ref == 'refs/heads/main'
concurrency:
group: deploy
cancel-in-progress: false
needs:
- build
steps:
- name: Checkout the repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Download build artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: dist
- name: Unpack build artifacts
run: tar -xf dist.tar && rm dist.tar
- name: Build Docker image
run: docker build -t ghcr.io/ORG/REPO:latest .
- name: Login to GitHub Container Registry
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push Docker image
run: docker push ghcr.io/ORG/REPO:latest
- name: Deploy image
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
let token = await core.getIDToken('https://api.cloud.hplush.dev')
let response = await fetch(
'https://api.cloud.hplush.dev/deploy/REPO',
{ method: 'POST', headers: { authorization: `Bearer ${token}` } }
)
let answer = await response.text()
if (response.ok) core.info(answer)
else core.setFailed(`${response.status} ${response.statusText}: ${answer}`)
- name: Clean previous images
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSIONS="orgs/ORG/packages/container/REPO/versions"
IDS=$(gh api --paginate "$VERSIONS?per_page=100" \
| jq -r '.[] | select(.metadata.container.tags == []) | .id')
if [ -n "$IDS" ]; then
for ID in $IDS; do
echo "Deleting version $ID"
gh api -X DELETE "$VERSIONS/$ID" --silent
done
else
echo "No untagged images"
fi