-
Notifications
You must be signed in to change notification settings - Fork 0
127 lines (114 loc) · 4.45 KB
/
Copy pathdeploy.yml
File metadata and controls
127 lines (114 loc) · 4.45 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
123
124
125
126
127
name: CI/CD Pipeline
on:
push:
branches:
- main
- "*"
jobs:
# Build stage - converting md file to html using MkDocs
convert_md_to_html:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' # Run for non-main branches
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Install MkDocs and dependencies
run: |
pip install mkdocs mkdocs-material
- name: Build project with MkDocs
run: |
echo "Building your project..."
mkdocs build
echo "pwd in build project with MKDocs"
pwd
- name: Debug MkDocs Build Output
run: |
echo "Contents of site directory:"
ls -l site
- name: Save artifacts
uses: actions/upload-artifact@v4
with:
name: site
path: site
# Deployment to test folder in S3 bucket
deploy_to_test:
needs: convert_md_to_html
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' # Run for non-main branches
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Get PR number from GitHub API
id: pr
run: |
PR_API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/commits/${GITHUB_SHA}/pulls"
PR_NUMBER=$(curl -s -H "Accept: application/vnd.github.groot-preview+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
$PR_API_URL | jq '.[0].number')
echo "pr_number=$PR_NUMBER"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: site
path: site
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1 # change if needed
- name: Deploy to Test Environment
env:
S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/commits/${GITHUB_SHA}/pulls"
PR_NUMBER=$(curl -s -H "Accept: application/vnd.github.groot-preview+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
$PR_API_URL | jq '.[0].number')
echo "pr_number while deploying =$PR_NUMBER"
pwd
#aws s3 ls
#aws s3 sync site/ s3://$S3_BUCKET_NAME/test
#aws s3 sync site/ s3://$S3_BUCKET_NAME/MergeRequest/$PR_NUMBER
# Deployment to production folder in S3 bucket
deploy_to_production:
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/main' # Run for main branch
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1 # change if needed
- name: Get PR number from GitHub API
id: pr
run: |
echo "Before pr_number=$PR_NUMBER"
PR_API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/commits/${GITHUB_SHA}/pulls"
PR_NUMBER=$(curl -s -H "Accept: application/vnd.github.groot-preview+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
$PR_API_URL | jq '.[0].number')
echo "after pr_number=$PR_NUMBER"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy to Production Environment
env:
S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "inside pr_number=$PR_NUMBER"
echo "Before pr_number=$PR_NUMBER"
PR_API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/commits/${GITHUB_SHA}/pulls"
PR_NUMBER=$(curl -s -H "Accept: application/vnd.github.groot-preview+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
$PR_API_URL | jq '.[0].number')
echo "after pr_number=$PR_NUMBER"
#aws s3 sync s3://$S3_BUCKET_NAME/MergeRequest/$PR_NUMBER s3://$S3_BUCKET_NAME/production/