|
5 | 5 | types: [published] |
6 | 6 |
|
7 | 7 | jobs: |
8 | | - demo: |
9 | | - name: Update demonstration, hosted on github pages |
| 8 | + build: |
| 9 | + name: Build for ${{ matrix.os }} (${{ matrix.arch }}) |
10 | 10 | runs-on: ubuntu-20.04 |
| 11 | + strategy: |
| 12 | + fail-fast: false |
| 13 | + matrix: |
| 14 | + os: [linux, darwin] # linux, freebsd, darwin, windows |
| 15 | + arch: [amd64] # amd64, 386 |
11 | 16 | steps: |
12 | | - - name: Check out code |
13 | | - uses: actions/checkout@v2 |
14 | | - |
15 | | - - name: Setup NodeJS |
16 | | - uses: actions/setup-node@v1 # Action page: <https://github.com/actions/setup-node> |
17 | | - with: |
18 | | - node-version: 15 |
| 17 | + - uses: actions/setup-go@v2 |
| 18 | + with: {go-version: 1.17.1} |
19 | 19 |
|
20 | | - - uses: actions/cache@v2 |
21 | | - with: |
22 | | - path: '**/node_modules' |
23 | | - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} |
| 20 | + - uses: actions/checkout@v2 |
24 | 21 |
|
25 | | - - name: Install dependencies |
26 | | - working-directory: generator |
27 | | - run: yarn install |
28 | | - |
29 | | - - name: Generate pages |
30 | | - run: ./generator/generator.js -i -c ./config.json -o ./out |
31 | | - |
32 | | - - name: Upload artifact |
33 | | - uses: actions/upload-artifact@v2 |
34 | | - with: |
35 | | - name: content |
36 | | - path: out/ |
37 | | - retention-days: 1 |
| 22 | + - uses: gacts/github-slug@v1 |
| 23 | + id: slug |
38 | 24 |
|
39 | | - - name: Switch to github pages branch |
40 | | - uses: actions/checkout@v2 |
41 | | - with: |
42 | | - ref: gh-pages |
43 | | - |
44 | | - - name: Download artifact |
45 | | - uses: actions/download-artifact@v2 |
| 25 | + - name: Generate builder values |
| 26 | + id: values |
| 27 | + run: echo "::set-output name=binary-name::error-pages-${{ matrix.os }}-${{ matrix.arch }}" |
| 28 | + |
| 29 | + - name: Build application |
| 30 | + env: |
| 31 | + GOOS: ${{ matrix.os }} |
| 32 | + GOARCH: ${{ matrix.arch }} |
| 33 | + CGO_ENABLED: 0 |
| 34 | + LDFLAGS: -s -w -X github.com/tarampampam/error-pages/internal/version.version=${{ steps.slug.outputs.version }} |
| 35 | + run: go build -trimpath -ldflags "$LDFLAGS" -o "./${{ steps.values.outputs.binary-name }}" ./cmd/error-pages/ |
| 36 | + |
| 37 | + - name: Upload binary file to release |
| 38 | + uses: svenstaro/upload-release-action@v2 |
46 | 39 | with: |
47 | | - name: content |
48 | | - |
49 | | - - name: Setup git |
50 | | - run: | |
51 | | - git config --global user.name "$GITHUB_ACTOR" |
52 | | - git config --global user.email '[email protected]' |
53 | | - git remote add github "https://$GITHUB_ACTOR:[email protected]/$GITHUB_REPOSITORY.git" |
54 | | -
|
55 | | - - name: Stage changes |
56 | | - run: git add . |
57 | | - |
58 | | - - name: Commit changes |
59 | | - run: git commit --allow-empty -m "Deploying ${GITHUB_SHA} to Github Pages" |
60 | | - |
61 | | - - name: Push changes |
62 | | - run: git push github --force |
| 40 | + repo_token: ${{ secrets.GITHUB_TOKEN }} |
| 41 | + file: ${{ steps.values.outputs.binary-name }} |
| 42 | + asset_name: ${{ steps.values.outputs.binary-name }} |
| 43 | + tag: ${{ github.ref }} |
63 | 44 |
|
64 | 45 | docker-image: |
65 | 46 | name: Build docker image |
66 | 47 | runs-on: ubuntu-20.04 |
67 | 48 | steps: |
68 | | - - name: Check out code |
69 | | - uses: actions/checkout@v2 |
| 49 | + - uses: actions/checkout@v2 |
| 50 | + |
| 51 | + - uses: gacts/github-slug@v1 |
| 52 | + id: slug |
70 | 53 |
|
71 | | - - name: Set up QEMU |
72 | | - uses: docker/setup-qemu-action@v1 # Action page: <https://github.com/docker/setup-qemu-action> |
| 54 | + - uses: docker/setup-qemu-action@v1 # Action page: <https://github.com/docker/setup-qemu-action> |
73 | 55 |
|
74 | | - - name: Set up Docker Buildx |
75 | | - uses: docker/setup-buildx-action@v1 # Action page: <https://github.com/docker/setup-buildx-action> |
| 56 | + - uses: docker/setup-buildx-action@v1 # Action page: <https://github.com/docker/setup-buildx-action> |
76 | 57 |
|
77 | | - - name: Login to default Container Registry |
78 | | - uses: docker/login-action@v1 # Action page: <https://github.com/docker/login-action> |
| 58 | + - uses: docker/login-action@v1 # Action page: <https://github.com/docker/login-action> |
79 | 59 | with: |
80 | 60 | username: ${{ secrets.DOCKER_LOGIN }} |
81 | 61 | password: ${{ secrets.DOCKER_PASSWORD }} |
82 | 62 |
|
83 | | - - name: Login to GitHub Container Registry |
84 | | - uses: docker/login-action@v1 # Action page: <https://github.com/docker/login-action> |
| 63 | + - uses: docker/login-action@v1 # Action page: <https://github.com/docker/login-action> |
85 | 64 | with: |
86 | 65 | registry: ghcr.io |
87 | 66 | username: ${{ github.actor }} |
88 | 67 | password: ${{ secrets.GHCR_PASSWORD }} |
89 | 68 |
|
90 | | - - name: Generate builder values |
91 | | - id: values |
92 | | - run: echo "::set-output name=version::${GITHUB_REF##*/[vV]}" # `/refs/tags/v1.2.3` -> `1.2.3` |
| 69 | + - uses: docker/build-push-action@v2 # Action page: <https://github.com/docker/build-push-action> |
| 70 | + with: |
| 71 | + context: . |
| 72 | + file: Dockerfile |
| 73 | + push: true |
| 74 | + platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7 |
| 75 | + build-args: "APP_VERSION=${{ steps.slug.outputs.version }}" |
| 76 | + tags: | |
| 77 | + tarampampam/error-pages:${{ steps.slug.outputs.version }} |
| 78 | + tarampampam/error-pages:latest |
| 79 | + ghcr.io/${{ github.actor }}/${{ github.event.repository.name }}:${{ steps.slug.outputs.version }} |
| 80 | + ghcr.io/${{ github.actor }}/${{ github.event.repository.name }}:latest |
93 | 81 |
|
94 | | - - name: Build image |
| 82 | + demo: |
| 83 | + name: Update the demonstration |
| 84 | + runs-on: ubuntu-20.04 |
| 85 | + needs: [docker-image] |
| 86 | + steps: |
| 87 | + - uses: gacts/github-slug@v1 |
| 88 | + id: slug |
| 89 | + |
| 90 | + - name: Take rendered templates from the built docker image |
95 | 91 | run: | |
96 | | - docker buildx build \ |
97 | | - --platform "linux/amd64,linux/arm64/v8,linux/arm/v6,linux/arm/v7" \ |
98 | | - --tag "tarampampam/error-pages:${{ steps.values.outputs.version }}" \ |
99 | | - --tag "tarampampam/error-pages:latest" \ |
100 | | - --tag "ghcr.io/${{ github.actor }}/error-pages:${{ steps.values.outputs.version }}" \ |
101 | | - --tag "ghcr.io/${{ github.actor }}/error-pages:latest" \ |
102 | | - --file ./Dockerfile \ |
103 | | - --push \ |
104 | | - . |
| 92 | + docker create --name img ghcr.io/${{ github.actor }}/${{ github.event.repository.name }}:${{ steps.slug.outputs.version }} |
| 93 | + docker cp img:/opt/html ./out |
| 94 | + docker rm -f img |
| 95 | +
|
| 96 | + - name: Deploy to GitHub Pages |
| 97 | + uses: peaceiris/actions-gh-pages@v3 |
| 98 | + with: |
| 99 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 100 | + publish_dir: ./out |
0 commit comments