-
Notifications
You must be signed in to change notification settings - Fork 23
129 lines (112 loc) · 4.66 KB
/
cd_pipeline.yml
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
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: ciroh-ua-website-cd
on:
workflow_run:
workflows: ["ciroh-ua-website-ci"]
branches:
- main
types:
- completed
workflow_call:
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
name: Deploy to GitHub Pages
steps:
# - name: Checkout
# uses: actions/checkout@v3
# with:
# fetch-depth: 0
# # Ensure detached HEAD state to avoid conflicts with the main branch
# ref: refs/heads/main
- name: Checkout Repo B
uses: actions/checkout@v2
with:
repository: CIROH-UA/ciroh-ua.github.io # Replace with the owner and name of Repo B
token: ${{ secrets.SECRET_TO_PUSH_TO_CIROH_GITHUB_IO }} # If Repo B is private, provide a personal access token with appropriate permissions
- name: Download a Build Artifact Version
uses: dawidd6/[email protected]
with:
workflow: ci_pipeline.yml
workflow_conclusion: success
branch: main
name: version
path: ./
- name: Read file and set variable
run: |
# Read file and set its value to a variable
FILE_CONTENT=$(cat ./version.txt)
# Set variable as an environment variable
echo "VERSION=$FILE_CONTENT" >> $GITHUB_ENV
- name: Display variable value
run: |
# Display value of variable
echo "My variable value is $VERSION"
# https://github.com/marketplace/actions/download-workflow-artifact
- name: Download a Build Artifact
uses: dawidd6/[email protected]
with:
workflow: ci_pipeline.yml
workflow_conclusion: success
branch: main
name: build
path: ./build/
# - name: Create and switch to a temporary deployment branch
# run: |
# git checkout -b temp-deploy-branch-$VERSION
# - name: Deploy to GitHub Pages
# uses: JamesIves/[email protected]
# with:
# token: ${{ secrets._REPO_SECRET_GITHUB_IO }}
# branch: main
# folder: build
# repository-name: CIROH-UA/ciroh-ua.github.io
- name: List contents of the build directory
run: |
echo "Contents of the build directory:"
ls -al ./build/
- name: Configure git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Clone GitHub Pages repository
env:
PERSONAL_ACCESS_TOKEN: ${{ secrets.SECRET_TO_PUSH_TO_CIROH_GITHUB_IO }}
run: |
git clone --single-branch --branch main https://ciroh-ua:${{ secrets.SECRET_TO_PUSH_TO_CIROH_GITHUB_IO }}@github.com/CIROH-UA/ciroh-ua.github.io.git gh-pages
rsync -av --delete-after ./build/ gh-pages/ # Copy the contents of the build directory
git checkout -b deploy-branch-$VERSION
git add .
git commit -m "Deploy from CI workflow artifact"
git push --set-upstream origin deploy-branch-$VERSION
# - name: Create a new branch for the changes and push to new branch
# working-directory: gh-pages
# run: |
# git checkout -b deploy-branch-$VERSION
# git add .
# git commit -m "Deploy from CI workflow artifact"
# - name: Push changes to new branch
# working-directory: gh-pages
# env:
# PERSONAL_ACCESS_TOKEN: ${{ secrets.SECRET_TO_PUSH_TO_CIROH_GITHUB_IO }}
# run: |
# git push --set-upstream origin deploy-branch-$VERSION
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.SECRET_TO_PUSH_TO_CIROH_GITHUB_IO }}
commit-message: "Deploy from CI workflow artifact"
branch: deploy-branch-$VERSION
title: "Deploy from CI"
body: "This is an automated PR to deploy changes from CI workflow."
base: main
# - name: Commit and push changes
# working-directory: gh-pages
# run: |
# git add .
# git commit -m "Deploy from CI workflow artifact" || echo "Nothing to commit"
# git push --set-upstream origin main