forked from bazel-contrib/bcr-ui
-
Notifications
You must be signed in to change notification settings - Fork 4
115 lines (103 loc) · 3.92 KB
/
deploy.yml
File metadata and controls
115 lines (103 loc) · 3.92 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
name: Build and Deploy
on:
push:
branches:
- 'main'
workflow_dispatch:
inputs:
bcrCommitHash:
description: 'Commit hash of the BCR repository to use as the source for the build'
type: string
workflow_call:
inputs:
basePath:
description: 'Base path for the build, see https://nextjs.org/docs/app/api-reference/config/next-config-js/basePath'
type: string
bcrCommitHash:
description: 'Commit hash of the BCR repository to use as the source for the build'
type: string
permissions:
# Required so we can deploy to the gh-pages branch
contents: write
# To post the PR preview link as a comment
pull-requests: write
jobs:
build-and-deploy:
concurrency: ci-${{ github.ref }} # Recommended if you intend to make multiple deployments in quick succession.
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v5
- name: Install direnv
run: |
sudo apt-get install -y direnv
eval "$(direnv hook bash)"
- name: Install required binaries
run: |
direnv allow .
eval "$(direnv export bash)"
# GHA steps run as non-interactive shells so they don't source the .bashrc
echo "PATH=$PATH" >> $GITHUB_ENV
bazel run //bin:bazel_env
- name: Install required packages
run: pnpm install --frozen-lockfile
- name: Checkout BCR submodule
run: |
git submodule update --init -- data/bazel-central-registry
- name: Unshallow BCR submodule (if needed)
working-directory: data/bazel-central-registry
run: |
if [ "$(git rev-parse --is-shallow-repository)" = "true" ]; then
git fetch --unshallow
fi
- name: Checkout latest commit of BCR submodule
if: ${{ !inputs.bcrCommitHash }}
working-directory: data/bazel-central-registry
run: |
git checkout origin/main
- name: Checkout specific commit of BCR submodule
if: ${{ inputs.bcrCommitHash }}
working-directory: data/bazel-central-registry
run: |
git checkout ${{ inputs.bcrCommitHash }}
- name: Find latest successful run of fetch_repo_metadata workflow
id: find-run
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
run_id=$(gh run list \
--workflow "fetch_repo_metadata.yml" \
--branch main \
--json databaseId,status,conclusion \
--jq 'map(select(.status=="completed" and .conclusion=="success")) | first | .databaseId')
echo "run_id=$run_id" >> $GITHUB_OUTPUT
- name: Download and extract metadata artifact
if: steps.find-run.outputs.run_id != ''
env:
GH_TOKEN: ${{ github.token }}
run: |
mkdir -p data/github_metadata
if ! gh run download ${{ steps.find-run.outputs.run_id }} \
--name github_metadata \
--dir data/github_metadata; then
echo "No github_metadata artifact found; continuing without it."
fi
- name: Build 🔧 # Outputs the result to the 'out' folder.
run: pnpm run build
env:
NEXT_PUBLIC_BASE_PATH: ${{ inputs.basePath }}
- name: Deploy PR Preview
env:
HAS_SECRET: ${{ secrets.BCR_UI_PREVIEW_PUBLISH }}
# Pull requests from forks won't have a token to publish
if: github.event_name == 'pull_request' && env.HAS_SECRET != ''
uses: rossjrw/pr-preview-action@9f77b1d057b494e662c50b8ca40ecc63f21e0887 # v1.6.2
with:
source-dir: ./out/
token: ${{ secrets.BCR_UI_PREVIEW_PUBLISH }}
deploy-repository: bazel-contrib/bcr-ui-preview
- name: Deploy to GitHub Pages
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: out