name: docker-build on: push: branches: - tyclipso tags: - v* # Run tests for any PRs. pull_request: env: REGISTRY: ghcr.io jobs: # Test building the docker image on pull requests test-build: runs-on: ubuntu-latest if: github.event_name == 'pull_request' steps: - name: Checkout repository uses: actions/checkout@v2 - name: Build image uses: docker/build-push-action@v2 with: push: false context: . file: dev/build/Dockerfile # Build image and push image to GitHub Packages. # See also https://docs.docker.com/docker-hub/builds/ build-and-push-image: runs-on: ubuntu-latest if: github.event_name == 'push' permissions: contents: read packages: write steps: - name: Checkout repository uses: actions/checkout@v2 - name: Log in to the Container registry uses: docker/login-action@v1 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata for Docker for tag id: meta_tag if: startsWith(github.ref, 'refs/tags/v') uses: docker/metadata-action@v3 with: images: ${{ env.REGISTRY }}/${{ github.repository }} tags: | type=ref,event=tag - name: Extract metadata for Docker on branch id: meta_edge if: false == startsWith(github.ref, 'refs/tags/v') uses: docker/metadata-action@v3 with: images: ${{ env.REGISTRY }}/${{ github.repository }} tags: | type=sha,prefix=,priority=200 type=edge,priority=100 - name: Get build time uses: gerred/actions/current-time@master id: build_time - name: Rewrite entries in package.json to match repository uses: microsoft/variable-substitution@v1 with: files: "package.json" env: releaseDate: ${{ steps.build_time.outputs.time }} repository.url: "git+${{ github.server_url }}/${{ github.repository }}.git" bugs.url: "${{ github.server_url }}/${{ github.repository }}/issues" homepage: "${{ github.server_url }}/${{ github.repository }}#readme" - name: Disable dev flag and set package version for tag if: startsWith(github.ref, 'refs/tags/v') uses: microsoft/variable-substitution@v1 with: files: "package.json" env: dev: "false" version: ${{ steps.meta_tag.outputs.version }} - name: Set package version for branch if: false == startsWith(github.ref, 'refs/tags/v') uses: microsoft/variable-substitution@v1 with: files: "package.json" env: version: ${{ steps.meta_edge.outputs.version }} - name: Build and push Docker image for tag if: startsWith(github.ref, 'refs/tags/v') uses: docker/build-push-action@v2 with: push: true context: . file: dev/build/Dockerfile tags: ${{ steps.meta_tag.outputs.tags }} labels: ${{ steps.meta_tag.outputs.labels }} - name: Build and push Docker image on branch if: false == startsWith(github.ref, 'refs/tags/v') uses: docker/build-push-action@v2 with: push: true context: . file: dev/build/Dockerfile tags: ${{ steps.meta_edge.outputs.tags }} labels: ${{ steps.meta_edge.outputs.labels }}