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

weru
06.54.2020 0e4bd2a85c8eebd7902a2b5c0b1c465ae6c71255
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
name: DeployCI
on:
  push:
    branches:
    - master
  pull_request:
    branches:
    - master
 
jobs:
  build:
  # In this phase, the code is pulled from master and the site rendered in Hugo. The built site is stored as an artifact for other stages.
    runs-on: ubuntu-latest
    steps:
    # Check out master branch from the repo.
    - name: Checkout master branch
      uses: actions/checkout@v2
 
    # Copy theme files into compose/ dir (do not commit)
    - name: Copy themes files temporarily
      id: can_duplicate
      run: |
        mkdir compose
        cp -a assets compose/assets
        cp -a layouts compose/layouts
        cp -a static compose/static
        cp theme.toml compose/theme.toml
 
    - name: Build site with Hugo
      uses: onweru/build-hugo@v0.75.1
 
    # If build succeeds, store the public/ dir as an artifact to be used in subsequent phases.
    - name: Upload output public dir as artifact
      uses: actions/upload-artifact@v1
      with:
        name: public
        path: exampleSite/public/
  publish:
  # In the publish phase, the site is pushed up to a different branch which only stores the exampleSite/public/ folder ("example" branch)
    runs-on: ubuntu-latest
    needs: build
    steps:
    # Check out the example branch this time since we have to ultimately commit those changes there.
    - name: Checkout example branch
      uses: actions/checkout@v2
      with:
        submodules: false
        fetch-depth: 0
        ref: ${{ env.SITE-BRANCH }}
    # Download the artifact containing the newly built site. This overwrites the public/ dir from the check out above.
    - name: Download artifact from build stage
      uses: actions/download-artifact@v1
      with:
        name: public
    # Add all the files/changes in public/ 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"
        git checkout -b example
        git rm -rf .
        mv --force exampleSite/public/* .
        git add .
        commit_message=$(git commit -m "Publish generated Hugo site." -a | tr -d '\n' || true)
        echo "::set-output name=commit_message::$commit_message"
    # 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 example branch
      if: steps.nothing_committed.conclusion == 'skipped'
      uses: ad-m/github-push-action@master
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        branch: example
        force: true