-
Notifications
You must be signed in to change notification settings - Fork 0
156 lines (132 loc) 路 6.61 KB
/
Copy pathbuild-page.yml
File metadata and controls
156 lines (132 loc) 路 6.61 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
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
name: Build and deploy static site
on:
# Trigger the workflow on push
push:
# Every branch
branches:
- "**"
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
# Set the environment variables to be used in all jobs defined in this workflow
# Set the CI_BRANCH environment variable to be the branch name
# NOTE: Use the same branch name as the one of EasyDiffractionLib. This is
# required to download the Jupyter notebooks from the EasyDiffractionLib repository
CI_BRANCH: ${{ github.head_ref || github.ref_name }}
REPOSITORY_NAME: diffraction
PROJECT_EMAIL: support@easydiffraction.org
jobs:
# Job 1: Build the static files for the documentation site
build-page:
runs-on: ubuntu-latest
steps:
- name: Cancel previous workflow runs
uses: n1hility/cancel-previous-runs@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Check-out repository
uses: actions/checkout@v4
# Download the template of the project landing page from the EasyScience/templates-page repository
- name: Download dependencies
working-directory: ..
run: git clone ${GITHUB_SERVER_URL}/EasyScience/templates-page
# Add the assets from the current project to the downloaded templates-page directory
- name: Add assets
run: cp -R assets ../templates-page/src/copy
# Create a config file with the repository name. This is used in the templates-page
- name: Create config
working-directory: ../templates-page
run: |
echo '{"project": "${{ env.REPOSITORY_NAME }}"}' > project.json
# Install npm dependencies needed to build the site in the templates-page directory
- name: Install npm dependencies
#working-directory: ../templates-page
run: |
cd ../templates-page
npm install
# Build the site in the templates-page directory
- name: Build site
#working-directory: ../templates-page
run: |
cd ../templates-page
npm run build
# Change the email in the contact.php file in the templates-page directory
- name: Change email in contact.php
#working-directory: ../templates-page
run: |
cd ../templates-page
node_modules/replace-in-file/bin/cli.js contact@easyscience.software ${{ env.PROJECT_EMAIL }} public/php/contact.php
# Copy the built site from the templates-page directory (../templates-page/public/) to
# the current project directory (site/)
- name: Copy built site to default working directory
run: cp -R ../templates-page/public/ site/
# Set up the Pages action to configure the static files to be deployed
# NOTE: The repository must have GitHub Pages enabled and configured to build using GitHub Actions
# This can be done via https://github.com/EasyScience/diffraction/settings/pages
# Select: Build and deploy - Source - GitHub Actions
- name: Setup GitHub Pages
uses: actions/configure-pages@v5
# Upload the static files from the site/ directory to be used in the next job
# This artifact is named github-pages and is a single gzip archive containing a single tar file
# The artifact is then used in the next job by actions/deploy-pages to deploy the static files to GitHub Pages
# Unfortunately, the artifact is not available for download, so extra steps below are needed to do similar things
- name: Upload built site as artifact (for github-pages, all branches)
uses: actions/upload-pages-artifact@v3
with:
path: site/
# Upload the static files from the site/ directory to be used in the next job
# This extra step is needed to allow the download of the artifact in the next job
# for pushing its content to the branch named 'easydiffraction.org'
- name: Upload built site as artifact (for easydiffraction.org, master branch only)
if: ${{ env.CI_BRANCH == 'master' }}
uses: actions/upload-artifact@v4
with:
name: artifact # name of the artifact (without the extension zip)
path: site/
if-no-files-found: "error"
compression-level: 0
# Job 2: Deploy the static files
# To allow the deployment of the static files to GitHub Pages
# No restrictions on the branch name is set on https://github.com/EasyScience/diffraction/settings/environments
deploy-docs:
needs: build-page # previous job 'build-page' need to be finished first
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
contents: read
pages: write # to deploy to Pages
id-token: write # to verify the deployment, originates from an appropriate source
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
# Deploy to the github-pages environment
environment:
name: github-pages # Artifact name
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
# Deploy the static files created in the previous job to GitHub Pages
# All branches are deployed to GitHub Pages and available at
# https://easyscience.github.io/diffraction
# This is needed for debugging purposes
- name: Deploy to easyscience.github.io/diffraction (all branches)
uses: actions/deploy-pages@v4
- name: Download built site as artifact from previous job (for easydiffraction.org, master branch only)
if: ${{ env.CI_BRANCH == 'master' }}
uses: actions/download-artifact@v4
with: # name or path are taken from the upload step of the previous job
name: artifact
path: site/ # directory to extract downloaded zipped artifacts
# Push the site files created in the previous job to the 'easydiffraction.org' branch
# This branch is used to deploy the site to the custom domain https://easydiffraction.org
# Deploying is done with a webhook: https://github.com/EasyScience/EasyDiffractionLibDocs/settings/hooks
# This is done for the 'master' branch only, when the site is tested with a step above
- name: Deploy to easydiffraction.org (master branch)
if: ${{ env.CI_BRANCH == 'master' }}
uses: s0/git-publish-subdir-action@develop
env:
GITHUB_TOKEN: ${{ secrets.API_TOKEN_GITHUB }}
REPO: self
BRANCH: easydiffraction.org
FOLDER: site