-
Notifications
You must be signed in to change notification settings - Fork 0
122 lines (114 loc) · 3.4 KB
/
Copy pathdeploy.yml
File metadata and controls
122 lines (114 loc) · 3.4 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
111
112
113
114
115
116
117
118
119
120
121
122
name: Deploy
on:
workflow_call:
workflow_dispatch:
inputs:
tag:
description: "Tag to build against"
required: true
default: "latest"
environment:
description: "Deployment environment"
required: true
default: "production"
type: choice
options:
- production
- staging
push:
branches:
- main
tags:
- "*"
env:
IMAGE_NAME: ghcr.io/anitrend/edge-graphql
CACHE_REF: ghcr.io/anitrend/edge-graphql:cache
permissions:
contents: read
jobs:
deploy:
name: Deploy Edge GraphQL
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
environment:
name: ${{ github.event.inputs.environment || 'production' }}
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set tag
id: set-tag
run: |
if [[ -n "${{ github.event.inputs.tag }}" ]]; then
tag=${{ github.event.inputs.tag }}
elif [[ "${{ github.ref }}" =~ ^refs/tags/ ]]; then
tag=${GITHUB_REF#refs/tags/}
else
tag=latest
fi
echo "Tag: $tag"
echo "tag=$tag" >> "$GITHUB_OUTPUT"
- name: Build and push snapshot image
uses: docker/build-push-action@v7
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
cache-from: type=registry,ref=${{ env.CACHE_REF }}
cache-to: type=registry,ref=${{ env.CACHE_REF }},mode=max
tags: ${{ env.IMAGE_NAME }}:${{ steps.set-tag.outputs.tag }}
notify:
name: Notify Deployment
runs-on: ubuntu-latest
needs: deploy
if: always()
permissions:
contents: read
steps:
- name: Notify success
if: needs.deploy.result == 'success'
run: |
echo "Deployed successfully!"
echo "Environment: ${{ github.event.inputs.environment || 'production' }}"
echo "Commit: ${{ github.sha }}"
echo "Timestamp: $(date -u)"
- name: Notify failure
if: needs.deploy.result == 'failure'
run: |
echo "Deployment failed!"
echo "Please check the deployment logs and try again."
exit 1
trigger-schema-sync:
name: Trigger AniTrend GraphQL Schema Sync
runs-on: ubuntu-latest
needs: deploy
if: needs.deploy.result == 'success' && startsWith(github.ref, 'refs/tags/')
permissions:
contents: read
steps:
- name: Create GitHub app token
uses: actions/create-github-app-token@v3
id: app-token
with:
client-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
owner: anitrend
repositories: edge-graphql,anitrend-v2
- name: Repository dispatch to AniTrend
uses: peter-evans/repository-dispatch@v4
with:
token: ${{ steps.app-token.outputs.token }}
repository: AniTrend/anitrend-v2
event-type: graphql-schema-sync
client-payload: '{"target":"anitrend"}'