Skip to content

Merge pull request #19 from flam-flam/issue/18 #22

Merge pull request #19 from flam-flam/issue/18

Merge pull request #19 from flam-flam/issue/18 #22

Workflow file for this run

---
name: CI
on:
push:
paths-ignore:
- README.md
- .gitignore
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/comment
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up NodeJS
uses: actions/setup-node@v3
with:
node-version: 14.x
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
version:
runs-on: ubuntu-latest
needs:
- test
permissions:
contents: write
outputs:
version_resolved: ${{ steps.resolve_version.outputs.version_resolved }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: '0'
- name: Tag and use it as version
if: github.ref == 'refs/heads/main'
uses: anothrNick/github-tag-action@8c8163ef62cf9c4677c8e800f36270af27930f42 # 1.61.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG_CONTEXT: branch
PRERELEASE: ${{ github.ref != 'refs/heads/main' }}
- uses: actions-ecosystem/action-get-latest-tag@b7c32daec3395a9616f88548363a42652b22d435 # v1.6.0
id: version_latest_tag
if: github.ref == 'refs/heads/main'
- name: Use branch name as version
if: github.ref != 'refs/heads/main'
id: version_branch_name
run: |
BRANCH_NAME=${GITHUB_REF#refs/heads/}
echo "Branch name: $BRANCH_NAME"
echo "branch_name=${BRANCH_NAME//\//_}" >> $GITHUB_OUTPUT
- name: Output resolved version
id: resolve_version
run: |
if [ -n "${{ steps.version_latest_tag.outputs.tag }}" ]; then
echo "version_resolved=${{ steps.version_latest_tag.outputs.tag }}" >> $GITHUB_OUTPUT
else
echo "version_resolved=${{ steps.version_branch_name.outputs.branch_name }}" >> $GITHUB_OUTPUT
fi
build:
needs:
- version
permissions:
packages: write
contents: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push image tag ${{ needs.version.outputs.version_resolved }}
env:
RESOLVED_VERSION: ${{needs.version.outputs.version_resolved}}
uses: docker/build-push-action@v3
with:
context: ${{ env.DOCKER_BUILD_CONTEXT }}
platforms: linux/amd64,linux/arm64
push: true
labels: ${{ steps.meta.outputs.labels }}
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.RESOLVED_VERSION }}
- name: Build and push 'latest' tag
uses: docker/build-push-action@v3
with:
context: ${{ env.DOCKER_BUILD_CONTEXT }}
platforms: linux/amd64,linux/arm64
push: ${{ github.ref == 'refs/heads/main' }}
labels: ${{ steps.meta.outputs.labels }}
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest