name: release on: push: branches: - master jobs: release-test: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2.3.4 - name: Setup Node.js uses: actions/setup-node@v2.1.4 with: node-version: 15 - name: Cache Node.js modules id: cache uses: actions/cache@v2.1.3 with: path: ~/.npm key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} restore-keys: | ${{ runner.os }}-node- - name: Cache hit run: echo ${{ steps.cache.outputs.cache-hit }} - name: Install dependencies run: npm ci env: SKIP_BUILD: true - name: Lint run: npm run lint -- --no-fix release-semantic: needs: release-test runs-on: ubuntu-latest outputs: published: ${{ steps.release.outputs.published }} release-version: ${{ steps.release.outputs.release-version }} release-version-major: ${{ steps.release.outputs.release-version-major }} release-version-minor: ${{ steps.release.outputs.release-version-minor }} steps: - name: Setup Node.js uses: actions/setup-node@v2.1.4 with: node-version: 15 - name: Turnstyle uses: softprops/turnstyle@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Checkout uses: actions/checkout@v2.3.4 - name: Cache Node.js modules id: cache uses: actions/cache@v2.1.3 with: path: ~/.npm key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} restore-keys: | ${{ runner.os }}-node- - name: Cache hit run: echo ${{ steps.cache.outputs.cache-hit }} - name: Install dependencies run: npm ci env: SKIP_BUILD: true - name: Semantic release id: release uses: ahmadnassri/action-semantic-release@v1.7.7 env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} npm_config_unsafe_perm: true release-alias: needs: release-semantic if: needs.release-semantic.outputs.published == 'true' runs-on: ubuntu-latest strategy: matrix: tag: - v${{ needs.release-semantic.outputs.release-version-major }} - v${{ needs.release-semantic.outputs.release-version-major }}.${{ needs.release-semantic.outputs.release-version-minor }} steps: - name: Recreate tag uses: actions/github-script@v3.1.0 with: script: | const tag = 'tags/${{ matrix.tag }}'; const repo = { owner: context.repo.owner, repo: context.repo.repo }; await github.git.deleteRef({ ...repo, ref: tag }).catch(() => {}); await github.git.createRef({ ...repo, ref: `refs/${tag}` , sha: process.env.GITHUB_SHA }); release-docker: needs: release-semantic if: needs.release-semantic.outputs.published == 'true' runs-on: ubuntu-latest strategy: fail-fast: false matrix: include: - dockerfile: Dockerfile docker-image: ${{ github.event.repository.full_name }} - dockerfile: Dockerfile.web docker-image: ${{ github.event.repository.full_name }}web steps: - name: Checkout uses: actions/checkout@v2.3.4 - name: Repo metadata id: repo uses: actions/github-script@v3.1.0 with: script: | const repo = await github.repos.get(context.repo) return repo.data - name: Prepare id: prep run: | echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') - name: Set up QEMU uses: docker/setup-qemu-action@v1.0.1 - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v1.1.1 with: version: latest - name: Available platforms run: echo ${{ steps.buildx.outputs.platforms }} - name: Get platforms uses: actions/github-script@v3.1.0 id: platforms env: DOCKER_CLI_EXPERIMENTAL: enabled with: result-encoding: string script: | const script = require(`${process.env.GITHUB_WORKSPACE}/.github/getDockerPlatforms.js`) return script("${{ matrix.dockerfile }}", "${{ steps.buildx.outputs.platforms }}"); - name: Platforms run: echo ${{ steps.platforms.outputs.result }} - name: Cache Docker layers uses: actions/cache@v2.1.3 id: cache with: path: /tmp/.buildx-cache key: ${{ runner.os }}-docker-${{ matrix.dockerfile }}-${{ hashFiles('**/package-lock.json') }}-${{ github.sha }} restore-keys: | ${{ runner.os }}-docker-${{ matrix.dockerfile }}-${{ hashFiles('**/package-lock.json') }} ${{ runner.os }}-docker-${{ matrix.dockerfile }}- ${{ runner.os }}-docker- - name: Cache hit run: echo ${{ steps.cache.outputs.cache-hit }} - name: Login to DockerHub uses: docker/login-action@v1.8.0 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Build and push id: docker-build uses: docker/build-push-action@v2.2.2 with: push: true builder: ${{ steps.buildx.outputs.name }} context: . file: ./${{ matrix.dockerfile}} platforms: ${{ steps.platforms.outputs.result }} tags: | ${{ matrix.docker-image }}:latest ${{ matrix.docker-image }}:${{ needs.release-semantic.outputs.release-version }} ${{ matrix.docker-image }}:${{ needs.release-semantic.outputs.release-version-major }}.${{ needs.release-semantic.outputs.release-version-minor }} ${{ matrix.docker-image }}:${{ needs.release-semantic.outputs.release-version-major }} labels: | org.opencontainers.image.title=${{ fromJson(steps.repo.outputs.result).name }} org.opencontainers.image.description=${{ fromJson(steps.repo.outputs.result).description }} org.opencontainers.image.url=${{ fromJson(steps.repo.outputs.result).html_url }} org.opencontainers.image.source=${{ fromJson(steps.repo.outputs.result).clone_url }} org.opencontainers.image.version=${{ needs.release-semantic.outputs.release-version }} org.opencontainers.image.created=${{ steps.prep.outputs.created }} org.opencontainers.image.revision=${{ github.sha }} org.opencontainers.image.licenses=${{ fromJson(steps.repo.outputs.result).license.spdx_id }} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache,mode=max build-args: | VERSION=${{ needs.release-semantic.outputs.release-version }} # - name: Update repo description # uses: peter-evans/dockerhub-description@v2.4.1 # with: # username: ${{ secrets.DOCKER_USERNAME }} # password: ${{ secrets.DOCKER_PASSWORD }} # repository: ${{ matrix.docker-image }} - name: Inspect run: | docker buildx imagetools inspect ${{ matrix.docker-image }}:${{ needs.release-semantic.outputs.release-version }} - name: Image digest run: echo ${{ steps.docker-build.outputs.digest }} - name: Dump context if: always() uses: crazy-max/ghaction-dump-context@v1.1.0