Merge pull request #412 from freee/dependabot/npm_and_yarn/multi-75e6… #354
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release and Deploy Documentation | |
| on: | |
| push: | |
| branches: | |
| - develop | |
| tags: | |
| - '[0-9][0-9][0-9][0-9][0-9][0-9].[0-9]*' | |
| workflow_dispatch: | |
| inputs: | |
| force_rebuild: | |
| description: 'Force rebuild all artifacts (ignore cache)' | |
| required: false | |
| default: false | |
| type: boolean | |
| target_ref: | |
| description: 'Target branch or tag to build (leave empty for current branch)' | |
| required: false | |
| default: '' | |
| type: string | |
| permissions: | |
| actions: read | |
| contents: write | |
| pages: write | |
| id-token: write | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: true | |
| jobs: | |
| check-repo: | |
| if: github.repository == 'freee/a11y-guidelines' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - run: echo "Running in the correct repository. Proceeding." | |
| get-build-targets: | |
| needs: check-repo | |
| uses: ./.github/workflows/reusable-get-build-targets.yml | |
| with: | |
| target_ref: ${{ inputs.target_ref || '' }} | |
| force_rebuild: ${{ inputs.force_rebuild || false }} | |
| check-existing-artifacts: | |
| runs-on: ubuntu-latest | |
| needs: get-build-targets | |
| outputs: | |
| reusable_artifacts: ${{ steps.check-artifacts.outputs.reusable_artifacts }} | |
| steps: | |
| - name: Check for existing artifacts | |
| id: check-artifacts | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| MATRIX: ${{ needs.get-build-targets.outputs.matrix }} | |
| FORCE_REBUILD: ${{ inputs.force_rebuild || 'false' }} | |
| run: | | |
| echo "Checking for reusable artifacts..." | |
| echo "Force rebuild mode: $FORCE_REBUILD" | |
| REUSABLE_ARTIFACTS="[]" | |
| # 強制再ビルドが指定されている場合は、アーティファクト検索をスキップ | |
| if [ "$FORCE_REBUILD" == "true" ]; then | |
| echo "Force rebuild enabled - skipping artifact search" | |
| else | |
| echo "Normal mode - searching for reusable artifacts" | |
| # 最新の成功したワークフロー実行を取得 | |
| RECENT_RUNS=$(gh run list \ | |
| --repo ${{ github.repository }} \ | |
| --workflow release.yml \ | |
| --status success \ | |
| --limit 5 \ | |
| --json databaseId,headSha,createdAt) | |
| # 各ビルドターゲットについて、既存のアーティファクトをチェック | |
| while IFS= read -r target; do | |
| TAG=$(echo "$target" | jq -r '.tag') | |
| ARTIFACT_NAME=$(echo "$target" | jq -r '.artifact_name') | |
| # タグ(develop以外)の場合、過去のアーティファクトを探す | |
| if [ "$TAG" != "develop" ]; then | |
| echo "Checking for existing artifact: $ARTIFACT_NAME for tag: $TAG" | |
| # 過去5回の実行からアーティファクトを検索 | |
| while IFS= read -r run; do | |
| RUN_ID=$(echo "$run" | jq -r '.databaseId') | |
| # アーティファクトの存在をチェック | |
| if gh api repos/${{ github.repository }}/actions/runs/$RUN_ID/artifacts --jq ".artifacts[] | select(.name == \"$ARTIFACT_NAME\") | .name" | grep -q "$ARTIFACT_NAME"; then | |
| echo "Found reusable artifact: $ARTIFACT_NAME in run: $RUN_ID" | |
| # 再利用可能なアーティファクトリストに追加 | |
| REUSABLE_ARTIFACTS=$(echo "$REUSABLE_ARTIFACTS" | jq -c --arg name "$ARTIFACT_NAME" --arg runId "$RUN_ID" '. + [{name: $name, runId: $runId}]') | |
| break | |
| fi | |
| done < <(echo "$RECENT_RUNS" | jq -c '.[]') | |
| fi | |
| done < <(echo "$MATRIX" | jq -c '.[]') # MODIFIED LINE: Process substitution for outer loop | |
| fi | |
| echo "reusable_artifacts=$REUSABLE_ARTIFACTS" >> $GITHUB_OUTPUT | |
| echo "Found $(echo "$REUSABLE_ARTIFACTS" | jq length) reusable artifacts" | |
| build-docs: | |
| needs: [get-build-targets, check-existing-artifacts] | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| build_target: ${{ fromJson(needs.get-build-targets.outputs.matrix) }} | |
| uses: ./.github/workflows/reusable-build-doc.yml | |
| with: | |
| tag: ${{ matrix.build_target.tag }} | |
| python: ${{ matrix.build_target.python }} | |
| sphinx: ${{ matrix.build_target.sphinx }} | |
| theme: ${{ matrix.build_target.theme }} | |
| deploy_path: ${{ matrix.build_target.deploy_path }} | |
| base_url: ${{ matrix.build_target.base_url }} | |
| artifact_name: ${{ matrix.build_target.artifact_name }} | |
| is_latest_release: ${{ matrix.build_target.is_latest_release || false }} | |
| is_latest_develop: ${{ matrix.build_target.is_latest_develop || false }} | |
| is_release_asset: ${{ matrix.build_target.release_asset || false }} | |
| vnum: ${{ matrix.build_target.vnum }} | |
| force_rebuild: ${{ inputs.force_rebuild || false }} | |
| reusable_artifacts: ${{ needs.check-existing-artifacts.outputs.reusable_artifacts }} | |
| secrets: inherit | |
| deploy-pages: | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| runs-on: ubuntu-latest | |
| needs: build-docs | |
| steps: | |
| - name: Setup Pages | |
| uses: actions/configure-pages@v4 | |
| - name: Download all build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: ${{ github.workspace }}/artifacts | |
| pattern: build-* | |
| - name: Prepare final deployment directory | |
| env: | |
| GITHUB_WORKSPACE: ${{ github.workspace }} | |
| run: | | |
| mkdir -p "${GITHUB_WORKSPACE}/_site" | |
| echo "Processing artifacts..." | |
| for artifact_dir in "${GITHUB_WORKSPACE}"/artifacts/*; do | |
| if [ -d "$artifact_dir" ]; then | |
| artifact_name=$(basename "$artifact_dir") | |
| echo "Processing artifact: $artifact_name" | |
| # Read deploy path from metadata | |
| if [ -f "${artifact_dir}/.deploy_path" ]; then | |
| deploy_path=$(cat "${artifact_dir}/.deploy_path") | |
| echo "Deploy path: $deploy_path" | |
| if [ -z "$deploy_path" ]; then | |
| # Root deployment | |
| echo "Deploying to root" | |
| cp -r "${artifact_dir}"/* "${GITHUB_WORKSPACE}/_site/" | |
| else | |
| # Subdirectory deployment | |
| echo "Deploying to subdirectory: $deploy_path" | |
| mkdir -p "${GITHUB_WORKSPACE}/_site/${deploy_path}" | |
| cp -r "${artifact_dir}"/* "${GITHUB_WORKSPACE}/_site/${deploy_path}/" | |
| fi | |
| # Remove metadata files from final deployment | |
| rm -f "${GITHUB_WORKSPACE}/_site/${deploy_path}/.deploy_path" 2>/dev/null || true | |
| rm -f "${GITHUB_WORKSPACE}/_site/${deploy_path}/.build_base_url" 2>/dev/null || true | |
| rm -f "${GITHUB_WORKSPACE}/_site/.deploy_path" 2>/dev/null || true | |
| rm -f "${GITHUB_WORKSPACE}/_site/.build_base_url" 2>/dev/null || true | |
| else | |
| echo "Warning: No .deploy_path found for $artifact_name" | |
| fi | |
| fi | |
| done | |
| - name: Upload Pages artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: ${{ github.workspace }}/_site | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 | |
| create-release: | |
| runs-on: ubuntu-latest | |
| needs: build-docs | |
| if: startsWith(github.ref, 'refs/tags/') | |
| env: | |
| GITHUB_WORKSPACE: ${{ github.workspace }} | |
| TAG: ${{ github.ref_name }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ env.TAG }} | |
| fetch-depth: 0 | |
| - name: Download asset build artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: ${{ github.workspace }}/artifacts | |
| pattern: release-* | |
| - name: Prepare release asset | |
| run: | | |
| ASSET_DIR="${GITHUB_WORKSPACE}/freee-a11y-guidelines-${TAG}" | |
| mkdir -p "${ASSET_DIR}" | |
| echo "Processing artifacts..." | |
| ARTIFACT_DIR="${GITHUB_WORKSPACE}/artifacts/release-${TAG}" | |
| if [ -d "$ARTIFACT_DIR" ]; then | |
| cp -r ${ARTIFACT_DIR}/* ${ASSET_DIR}/ | |
| # Remove metadata files from the asset | |
| rm -f "${ASSET_DIR}/.deploy_path" 2>/dev/null || true | |
| rm -f "${ASSET_DIR}/.build_base_url" 2>/dev/null || true | |
| zip -r ${GITHUB_WORKSPACE}/freee-a11y-guidelines-${TAG}-html.zip ./freee-a11y-guidelines-${TAG} | |
| else | |
| echo "ERROR: No artifact found for ${TAG}" | |
| exit 1 | |
| fi | |
| - name: Create GitHub Release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| RELEASE_NOTES_FILE="${GITHUB_WORKSPACE}/ja/source/intro/ChangeLog/${TAG:0:4}/${TAG}.rst" | |
| if [ -f "$RELEASE_NOTES_FILE" ]; then | |
| gh release create ${TAG} \ | |
| --title "Ver. ${TAG}" \ | |
| --notes-file "$RELEASE_NOTES_FILE" \ | |
| --draft | |
| else | |
| gh release create ${TAG} \ | |
| --title "Ver. ${TAG}" \ | |
| --notes "Release version ${TAG}" \ | |
| --draft | |
| fi | |
| gh release upload ${TAG} ${GITHUB_WORKSPACE}/freee-a11y-guidelines-${TAG}-html.zip |