Skip to content

Commit 0c5578e

Browse files
committed
Add environments
1 parent 8cc548a commit 0c5578e

File tree

1 file changed

+73
-51
lines changed

1 file changed

+73
-51
lines changed

.github/workflows/deploy-sdk.yml

Lines changed: 73 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010

1111
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
1212
permissions:
13-
contents: read
13+
contents: write
1414
pages: write
1515
id-token: write
1616

@@ -101,9 +101,10 @@ jobs:
101101
runs-on: ubuntu-latest
102102
permissions:
103103
contents: write
104-
# environment: deploy
104+
environment: deploy
105105
outputs:
106106
npm_tag: ${{ steps.determine_npm_tag.outputs.npm_tag }}
107+
version: ${{ steps.get_tag.outputs.tag }}
107108
steps:
108109
- name: Checkout sources
109110
uses: actions/checkout@v5
@@ -112,9 +113,7 @@ jobs:
112113

113114
- name: Extract tag name
114115
id: get_tag
115-
# ${GITHUB_REF#refs/tags/sdk/}
116-
# Hardcoded for testing
117-
run: echo "tag=10.0.1" >> $GITHUB_OUTPUT
116+
run: echo "tag=${GITHUB_REF#refs/tags/sdk/}" >> $GITHUB_OUTPUT
118117

119118
- name: Test that tag version matches package.json version
120119
run: test "${{ steps.get_tag.outputs.tag }}" = "$(jq -r ".version" packages/sdk/package.json)" || exit 1
@@ -130,38 +129,37 @@ jobs:
130129
fi
131130
echo "npm_tag=$npm_tag" >> $GITHUB_OUTPUT
132131
133-
# - name: Get build-output
134-
# uses: actions/download-artifact@v5
135-
# with:
136-
# name: build-release
137-
# path: packages/sdk
138-
139-
# - uses: actions/setup-node@v4
140-
# with:
141-
# node-version: ${{ env.NODE_VERSION }}
142-
# cache: yarn
143-
# registry-url: 'https://registry.npmjs.org'
144-
145-
# - name: Publish to NPM
146-
# run: |
147-
# yarn config set npmAuthToken $NPM_AUTH_TOKEN
148-
# yarn workspace @concordium/web-sdk npm publish --tag ${{ steps.determine_npm_tag.outputs.npm_tag }}
149-
# env:
150-
# NPM_AUTH_TOKEN: '${{secrets.NPM_PUBLISH_TOKEN}}'
151-
152-
# - name: Create a GitHub release
153-
# uses: ncipollo/release-action@v1
154-
# with:
155-
# tag: sdk/${{ steps.get_tag.outputs.tag }}
156-
# name: SDK Release v${{ steps.get_tag.outputs.tag }}
157-
# draft: true
132+
- name: Get build-output
133+
uses: actions/download-artifact@v5
134+
with:
135+
name: build-release
136+
path: packages/sdk
137+
138+
- uses: actions/setup-node@v4
139+
with:
140+
node-version: ${{ env.NODE_VERSION }}
141+
cache: yarn
142+
registry-url: 'https://registry.npmjs.org'
143+
144+
- name: Publish to NPM
145+
run: |
146+
yarn config set npmAuthToken $NPM_AUTH_TOKEN
147+
yarn workspace @concordium/web-sdk npm publish --tag ${{ steps.determine_npm_tag.outputs.npm_tag }}
148+
env:
149+
NPM_AUTH_TOKEN: '${{secrets.NPM_PUBLISH_TOKEN}}'
150+
151+
- name: Create a GitHub release
152+
uses: ncipollo/release-action@v1
153+
with:
154+
tag: sdk/${{ steps.get_tag.outputs.tag }}
155+
name: SDK Release v${{ steps.get_tag.outputs.tag }}
156+
draft: true
158157

159158
deploy-typedoc:
160159
needs:
161160
- upload-release
162-
# environment:
163-
# name: github-pages
164-
# url: ${{ steps.deployment.outputs.page_url }}
161+
environment:
162+
name: github-pages
165163
runs-on: ubuntu-22.04
166164
steps:
167165
- name: Checkout
@@ -173,28 +171,52 @@ jobs:
173171
path: typedoc
174172
name: typedoc-build
175173

176-
- name: Setup Pages
177-
uses: actions/configure-pages@v5
174+
# Clone old `gh-pages` branch so we can later build a list of
175+
# available documentation versions.
176+
- name: Clone old gh-pages content
177+
run: |
178+
# Make a local work folder
179+
mkdir -p gh-pages
178180
179-
# Put docs into a versioned subfolder
180-
- name: Move typedoc into versioned folder
181+
# Copy its content into local `gh-pages` folder
182+
git clone --branch gh-pages --depth 1 https://github.com/${{ github.repository }} old-gh-pages
183+
cp -r old-gh-pages/* gh-pages/ || true
184+
185+
# Put new docs into a versioned subfolder
186+
- name: Generate versioned subfolder
181187
run: |
182-
VERSION=${{ steps.get_tag.outputs.tag }}
183-
mkdir -p docs/$VERSION
184-
cp -r typedoc/* docs/latest
188+
VERSION=${{ needs.upload-release.outputs.version }}
189+
mkdir -p gh-pages/$VERSION
190+
cp -r typedoc/* gh-pages/$VERSION
185191
186-
# (Optional) symlink "latest" newest tag
187-
- name: Update latest symlink
192+
# Update the "latest" subfolder content with the newest doc version.
193+
- name: Update `latest` subfolder content
188194
if: needs.upload-release.outputs.npm_tag == 'latest'
189195
run: |
190-
rm -rf docs/latest
191-
mv typedoc/* docs/$VERSION
196+
mkdir -p gh-pages/latest
197+
rm -rf gh-pages/latest/*
198+
cp -r typedoc/* gh-pages/latest
192199
193-
- name: Upload GH Pages artifact
194-
uses: actions/upload-pages-artifact@v3
195-
with:
196-
path: './docs'
200+
# Generate list of available documentation versions.
201+
# This needs to be done after the `gh-pages` branch has been fetched with the old docs.
202+
- name: Generate docs index
203+
run: |
204+
echo "<!DOCTYPE html>" > gh-pages/index.html
205+
echo "<html><head><title>Documentation Versions</title></head><body>" >> gh-pages/index.html
206+
echo "<h1>Available Documentation Versions</h1><ul>" >> gh-pages/index.html
207+
208+
# Loop over all directories in gh-pages/
209+
for d in gh-pages/*/ ; do
210+
version=$(basename "$d")
211+
echo "<li><a href=\"./$version/\">$version</a></li>" >> gh-pages/index.html
212+
done
197213
198-
- name: Deploy to GitHub Pages
199-
id: deployment
200-
uses: actions/deploy-pages@v4
214+
echo "</ul>" >> gh-pages/index.html
215+
echo "</body></html>" >> gh-pages/index.html
216+
217+
- name: Deploy
218+
uses: peaceiris/actions-gh-pages@v4
219+
with:
220+
github_token: ${{ secrets.GITHUB_TOKEN }}
221+
publish_dir: ./gh-pages
222+
keep_files: true

0 commit comments

Comments
 (0)