1616 - build-and-test
1717 permissions :
1818 id-token : write
19+ outputs :
20+ new_release : ${{ steps.check_release.outputs.new_release }}
21+ release_tag : ${{ steps.check_release.outputs.release_tag }}
1922 steps :
2023 - uses : actions/checkout@v6
2124 with :
3033 name : dist
3134 path : dist
3235 - run : npm ci --prefer-offline --no-audit
36+
37+ - id : before_release
38+ run : |
39+ BEFORE_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
40+ echo "before_tag=$BEFORE_TAG" >> $GITHUB_OUTPUT
41+
3342 - run : npx semantic-release
3443 env :
3544 SKIP_COMMIT : ${{ github.ref_name == 'next' && 'true' || '' }}
@@ -38,3 +47,147 @@ jobs:
3847 GIT_COMMITTER_NAME : ' Siemens Element Bot'
3948 GIT_COMMITTER_EMAIL : ' simpl.si@siemens.com'
4049 GITHUB_TOKEN : ${{ secrets.ELEMENT_BOT_GITHUB_TOKEN }}
50+
51+ - id : check_release
52+ run : |
53+ BEFORE_TAG="${{ steps.before_release.outputs.before_tag }}"
54+ AFTER_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
55+
56+ if [[ -n "$AFTER_TAG" && "$AFTER_TAG" != "$BEFORE_TAG" ]]; then
57+ echo "release_tag=$AFTER_TAG" >> $GITHUB_OUTPUT
58+ echo "new_release=true" >> $GITHUB_OUTPUT
59+ else
60+ echo "new_release=false" >> $GITHUB_OUTPUT
61+ echo "release_tag=" >> $GITHUB_OUTPUT
62+ fi
63+
64+ # Generates the versioned documentation and publishes it to S3.
65+ # This job only runs after a successful release unless the release is on the "next" branch.
66+ # In general, runs on main push to /latest/, while release branches (e.g., release/48.x) push to /v48/
67+ # There are two special cases:
68+ # 1. Release on a release branch while there is no new major release on main.
69+ # This happens, when we already merged breaking changes, but do a release for an older version before releasing from main.
70+ # In this case, we still want to update the /latest/ although we are on a release branch.
71+ # 2. The first release of a new major version.
72+ # In this case, we need to move the existing /latest/ to the previous major version folder.
73+ publish-documentation-release :
74+ runs-on : ubuntu-24.04
75+ needs :
76+ - publish
77+ - build-and-test
78+ if : success() && needs.publish.outputs.new_release == 'true' && github.ref_name != 'next'
79+ permissions :
80+ id-token : write
81+ env :
82+ VERSIONED_BUCKET_NAME : simpl-element-release
83+ CLOUDFRONT_DOMAIN : d2uqfzn4lxgtwv.cloudfront.net
84+ steps :
85+ - uses : actions/checkout@v4
86+ with :
87+ fetch-depth : 0
88+ - uses : actions/download-artifact@v7
89+ with :
90+ name : pages
91+ path : pages
92+ - uses : aws-actions/configure-aws-credentials@v5.1.1
93+ with :
94+ role-to-assume : arn:aws:iam::974483672234:role/simpl-element-release
95+ role-session-name : element-release-docs
96+ aws-region : eu-west-1
97+ # Prepare gathers the necessary information:
98+ # - the version / major version we are releasing
99+ # - to which directory we need to deploy (latest or v123)
100+ # - latest-version.txt contains the current version of the "latest" object in the S3 bucket
101+ # If we create a new major version, we also move the existing latest/ to the previous major version folder.
102+ # This outputs three values:
103+ # - major_version: the major version we are releasing (e.g., v49)
104+ # - deploy_latest: whether we need to deploy to latest/ (true/false)
105+ # - latest: the current version of latest/ before this release (e.g., v48)
106+ - id : prepare
107+ run : |
108+ DEPLOY_RELEASE="${{ needs.publish.outputs.release_tag }}"
109+ VERSION="${DEPLOY_RELEASE#v}"
110+ MAJOR_VERSION="v${VERSION%%.*}"
111+
112+ echo "major_version=$MAJOR_VERSION" >> "$GITHUB_OUTPUT"
113+
114+ aws s3 cp "s3://${{ env.VERSIONED_BUCKET_NAME }}/latest-version.txt" latest-version.txt || true
115+
116+ LATEST_VERSION=""
117+ if [[ -f latest-version.txt ]]; then
118+ LATEST_VERSION=$(tr -d '\r\n' < latest-version.txt)
119+ fi
120+
121+ DEPLOY_LATEST="false"
122+
123+ # if [[ "${{ github.ref_name }}" == "${{ github.event.repository.default_branch }}" ]]; then
124+ if [[ "a" == "a" ]]; then
125+ DEPLOY_LATEST="true"
126+ if [[ -n "$LATEST_VERSION" && "$LATEST_VERSION" != "$MAJOR_VERSION" ]]; then
127+ aws s3 sync --quiet --no-progress --delete \
128+ "s3://${{ env.VERSIONED_BUCKET_NAME }}/latest/" \
129+ "s3://${{ env.VERSIONED_BUCKET_NAME }}/$LATEST_VERSION/"
130+ fi
131+ elif [[ "$LATEST_VERSION" == "$MAJOR_VERSION" ]]; then
132+ DEPLOY_LATEST="true"
133+ fi
134+
135+ echo "deploy_latest=$DEPLOY_LATEST" >> "$GITHUB_OUTPUT"
136+ echo "latest=$LATEST_VERSION" >> "$GITHUB_OUTPUT"
137+
138+ aws s3 ls s3://${{ env.VERSIONED_BUCKET_NAME }}/ | grep "PRE v" | awk '{print $2}' | sed 's/\/$//' | sed 's/^v//' > s3-versions.txt || true
139+
140+ # Generate versions.json based on the existing versions in S3 and the new release
141+ - uses : actions/github-script@v7
142+ name : Generate versions.json
143+ with :
144+ script : |
145+ const fs = require('fs');
146+
147+ const rawVersions = fs
148+ .readFileSync('s3-versions.txt', 'utf8')
149+ .split(/\r?\n/)
150+ .map(line => line.trim())
151+ .filter(Boolean);
152+
153+ const payload = rawVersions
154+ .sort((a, b) => Number(b) - Number(a))
155+ .map(versionName => ({
156+ version: `v${versionName}`,
157+ title: `${versionName}.x`
158+ }));
159+
160+ if (${{ steps.prepare.outputs.deploy_latest == 'true' }}) {
161+ const majorVersion = "${{ steps.prepare.outputs.major_version }}";
162+ const numericTitle = majorVersion.replace(/^v/i, '');
163+ payload.unshift({ version: '', title: `${numericTitle}.x` });
164+ } else {
165+ const latestFallback = "${{ steps.prepare.outputs.latest }}";
166+ const numericTitle = latestFallback.replace(/^v/i, '');
167+ payload.unshift({ version: '', title: `${numericTitle}.x` });
168+ }
169+
170+ fs.writeFileSync('versions.json', JSON.stringify(payload, null, 2));
171+
172+ # Uploads the generated documentation to the appropriate S3 bucket and path.
173+ - run : |
174+ SITE_URL="https://element.siemens.io/"
175+
176+ # Update canonical URLs to point to versioned URLs instead of root
177+ # This ensures search engines index the correct versioned documentation (only one version)
178+ MAJOR_VERSION="${{ steps.prepare.outputs.major_version }}"
179+
180+ if [[ "${{ steps.prepare.outputs.deploy_latest }}" == "true" ]]; then
181+ aws s3 sync --quiet --no-progress --delete "pages/" "s3://${{ env.VERSIONED_BUCKET_NAME }}/latest/"
182+ echo "$MAJOR_VERSION" > latest-version.txt
183+ aws s3 cp latest-version.txt "s3://${{ env.VERSIONED_BUCKET_NAME }}/latest-version.txt"
184+ else
185+ aws s3 sync --quiet --no-progress --delete "pages/" "s3://${{ env.VERSIONED_BUCKET_NAME }}/$MAJOR_VERSION/"
186+ fi
187+
188+ # Upload versions.json with short cache-control for quick updates
189+ if [[ ! -f "deploy-site/versions.json" ]]; then
190+ echo "Error: deploy-site/versions.json file does not exist"
191+ exit 1
192+ fi
193+ aws s3 cp versions.json s3://${{ env.VERSIONED_BUCKET_NAME }}/versions.json
0 commit comments