summaryrefslogtreecommitdiff
path: root/.github/workflows/push.yml
blob: 94d8cb9aa75e658395fb1fdf479af7f54c7e78f9 (plain)
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
on: [push]
name: Deploy workflow
concurrency:
  group: build-${{ github.ref }}
  cancel-in-progress: true
jobs:
  install:
    runs-on: ubuntu-20.04
    strategy:
      matrix:
        node-version: [16.x]

    steps:
      - uses: actions/checkout@v3

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}

      - name: Cache pnpm modules
        uses: actions/cache@v3
        with:
          path: ~/.pnpm-store
          key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
          restore-keys: |
            ${{ runner.os }}-

      - uses: pnpm/[email protected]
        with:
          version: 7
          run_install: true

      - name: Lint
        run: pnpm lint
      - name: Build
        run: pnpm build

      - name: Create Release
        if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/')
        id: create_release
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ github.ref }}
          release_name: ${{ github.ref }}
          draft: true
          prerelease: false
      - name: Create Tar Ball
        if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/')
        run: tar cJf yacd.tar.xz public
      - name: Upload Release Asset
        if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/')
        id: upload-release-asset
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ steps.create_release.outputs.upload_url }}
          asset_path: ./yacd.tar.xz
          asset_name: yacd.tar.xz
          asset_content_type: application/x-gzip

      - name: Push to gh-pages
        if: github.event_name == 'push' && (startsWith(github.event.ref, 'refs/tags/') || github.event.ref == 'refs/heads/publish')
        env:
          GITHUB_TOKEN: ${{ secrets.TOKEN }}
          PUBLISH_DIR: public
          BRANCH: gh-pages
        run: |
          cd $PUBLISH_DIR
          ls -l
          git init
          git config user.name "${GITHUB_ACTOR}"
          git config user.email "${GITHUB_ACTOR}@noreply.github.com"
          git add .
          git status
          git commit -m "Push to gh-pages"
          git push -f https://$GITHUB_ACTOR:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git HEAD:$BRANCH

      - name: Send Notification
        uses: haishanh/actions-telegram-notification@v1
        if: ${{ always() }}
        with:
          notification-token: ${{ secrets.TG_NOTIFICATION_TOKEN }}
          job-status: ${{ job.status }}

  docker:
    needs: install
    runs-on: ubuntu-20.04
    if: github.event_name == 'push' && (startsWith(github.event.ref, 'refs/tags/') || startsWith(github.event.ref, 'refs/heads/v0.') || github.event.ref == 'refs/heads/master' || github.event.ref == 'refs/heads/test')
    steps:
      - uses: actions/checkout@v3

      - name: Cache Docker layers
        uses: actions/cache@v3
        with:
          path: /tmp/.buildx-cache
          key: ${{ runner.os }}-buildx-${{ github.sha }}
          restore-keys: |
            ${{ runner.os }}-buildx-

      - name: Docker meta
        id: docker_meta
        uses: docker/metadata-action@v4
        with:
          images: haishanh/yacd

      # - name: Set up QEMU
      #   uses: docker/[email protected]

      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v2
        with:
          version: latest

      - name: Builder instance name
        run: echo ${{ steps.buildx.outputs.name }}
      - name: Available platforms
        run: echo ${{ steps.buildx.outputs.platforms }}

      - name: Login to Docker Hub
        uses: docker/login-action@v2
        with:
          username: ${{ github.actor }}
          password: ${{ secrets.DOCKER_HUB_PASSWORD }}

      - name: Login to GHCR
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and push
        id: docker_build
        uses: docker/build-push-action@v3
        with:
          context: .
          file: ./Dockerfile
          platforms: linux/amd64,linux/arm/v7,linux/arm64
          push: true
          tags: ${{ steps.docker_meta.outputs.tags }},ghcr.io/${{ steps.docker_meta.outputs.tags }}
          labels: ${{ steps.docker_meta.outputs.labels }}
          cache-from: type=gha
          cache-to: type=gha

      - name: Image digest
        run: echo ${{ steps.docker_build.outputs.digest }}

      - name: Send Notification
        uses: haishanh/actions-telegram-notification@v1
        if: ${{ always() }}
        with:
          notification-token: ${{ secrets.TG_NOTIFICATION_TOKEN }}
          job-status: ${{ job.status }}