mirror of https://github.com/onweru/compose.git

weru
29.59.2025 5c3ee289b1166a4e9af65745223db23f39716e04
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
name: UPDATE ALGOLIA INDEX
 
on:
  workflow_dispatch:
    branches:
    - production
  push:
    paths:
      - content/**/*
      # - hugo.toml
 
env:
  # Name of the branch in your repository which will store your generated site.
  SITE-BRANCH: master
 
jobs:
  build:
  # In this phase, the code is pulled from main and the site rendered in Hugo. The built site is stored as an artifact for other stages. # deploy:
    runs-on: ubuntu-20.04
    concurrency:
      group: ${{ github.workflow }}-${{ github.ref }}
    steps:
    - uses: actions/checkout@v3
      with:
        submodules: true  # Fetch Hugo themes (true OR recursive)
        fetch-depth: 0    # Fetch all history for .GitInfo and .Lastmod
 
    - name: Setup Hugo
      uses: peaceiris/actions-hugo@v2
      with:
        hugo-version: 'latest'
        extended: true
 
    - name: Build
      run: hugo -e "production" -s "exampleSite" -d "dist" --minify
    # If build succeeds, store the dist/ dir as an artifact to be used in subsequent phases.
    - name: Upload output dist dir as artifact
      uses: actions/upload-artifact@v1
      with:
        name: dist
        path: dist/
  publish:
  # In the publish phase, the site is pushed up to a different branch which only stores the dist/ folder ("site" branch) and is also delta synchronized to the S3 bucket. CloudFront invalidation happens last.
    runs-on: ubuntu-20.04
    needs: build
    steps:
    # Check out the site branch this time since we have to ultimately commit those changes there.
    - name: Checkout site branch
      uses: actions/checkout@v3
      with:
        submodules: true
        fetch-depth: 0
        ref: ${{ env.SITE-BRANCH }}
    # Download the artifact containing the newly built site. This overwrites the dist/ dir from the check out above.
    - name: Download artifact from build stage
      uses: actions/download-artifact@v1
      with:
        name: dist
    # Add all the files/changes in dist/ that were pulled down from the build stage and then commit them.
    # The final line sets a GitHub Action output value that can be read by other steps.
    # This function cannot store mult-line values so newline chars must be stripped.
    - name: Commit files
      id: can_commit
      run: |
        git config --local user.email "action@github.com"
        git config --local user.name "GitHub Action"
        cp dist/index.json index.json
        git add -A index.json
        commit_message=$(git commit -m "Build search index." -a | tr -d '\n' || true)
        echo "commit_message=$commxit_message >> $GITHUB_OUTPUT"
    # Checks if previous stage had any valid commit.
    - name: Nothing to commit
      id: nothing_committed
      if: contains(steps.can_commit.outputs.commit_message, 'nothing to commit')
      run: echo "Saw that no changes were made to Hugo site."
    # Push those changes back to the site branch.
    - name: Push to site branch
      if: steps.nothing_committed.conclusion == 'skipped'
      uses: ad-m/github-push-action@master
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        branch: ${{ env.SITE-BRANCH }}
  index:
    runs-on: ubuntu-latest
    needs: publish
    name: Upload Algolia Index
    steps:
    - uses: algolia/setup-algolia-cli@master
      with:
        version:
          1.2.0
    - name: clean index
      id: clean_up_index
      env:
        ALGOLIA_APPLICATION_ID: ${{ secrets.ALGOLIA_APP_ID }}
        ALGOLIA_ADMIN_API_KEY: ${{ secrets.ALGOLIA_ADMIN_KEY }}
      run: |
        algolia index clear dimi_site --confirm
    - uses: actions/checkout@v2
      with:
        fetch-depth: 0
    - uses: wangchucheng/algolia-uploader@master
      with:
        # Such as `Z0U0ACGBN8`
        app_id: EG0M7UVCD9
        # Go to https://github.com/dimi365/website/settings/secrets/actions and set an ALGOLIA_ADMIN_KEY secret key
        admin_key: ${{ secrets.ALGOLIA_ADMIN_KEY }}
        # The index name.
        index_name: ${{ secrets.ALGOLIA_APP_NAME }}
        # The index file path relative to repo root. no leading forward slash
        index_file_path: index.json