From 2d78bf855040ef9d84141ce400a42acfedc29db3 Mon Sep 17 00:00:00 2001 From: mpapenbr Date: Wed, 28 Dec 2022 22:55:07 +0100 Subject: [PATCH] build(gha): update github actions --- .github/workflows/docker-image.yml | 44 +++++++++++++++++++++++------- .github/workflows/nodejs.yml | 6 ++-- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index ceacb8c..604ca2f 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -3,12 +3,35 @@ on: push: tags: - "*" + workflow_dispatch: jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v3 + + - name: Prep + id: prep + run: | + GHCR_IMAGE=ghcr.io/${{ github.repository_owner }}/istint-web + VERSION=edge + if [[ $GITHUB_REF == refs/tags/* ]]; then + VERSION=${GITHUB_REF#refs/tags/} + elif [[ $GITHUB_REF == refs/heads/* ]]; then + VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g') + elif [[ $GITHUB_REF == refs/pull/* ]]; then + VERSION=pr-${{ github.event.number }} + fi + TAGS="${GHCR_IMAGE}:${VERSION}" + if [ "${{ github.event_name }}" = "push" ]; then + TAGS="$TAGS,${GHCR_IMAGE}:sha-${GITHUB_SHA::8}" + fi + echo "version=${VERSION}" >> $GITHUB_OUTPUT + echo "tags=${TAGS}" >> $GITHUB_OUTPUT + echo "ghcr_image=${GHCR_IMAGE}" >> $GITHUB_OUTPUT + echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT + - name: Cache node modules uses: actions/cache@v2 env: @@ -22,7 +45,7 @@ jobs: ${{ runner.os }}-build- ${{ runner.os }}- - name: Use Node.js 18 - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: node-version: "18" - name: Install dependencies @@ -38,12 +61,13 @@ jobs: CI: false - name: Copy to docker run: cp -r build/ docker/build - - name: Build and push docker image - uses: docker/build-push-action@v1 + - name: Build and push + uses: docker/build-push-action@v2 with: - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - path: docker - registry: docker.pkg.github.com - repository: mpapenbr/istint/istint-web - tag_with_ref: true + context: docker + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.prep.outputs.tags }} + labels: | + org.opencontainers.image.source=${{ github.event.repository.html_url }} + org.opencontainers.image.created=${{ steps.prep.outputs.created }} + org.opencontainers.image.revision=${{ github.sha }} diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 777d254..a034206 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -8,9 +8,9 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v3 - name: Cache node modules - uses: actions/cache@v2 + uses: actions/cache@v3 env: cache-name: cache-node-modules with: @@ -22,7 +22,7 @@ jobs: ${{ runner.os }}-build- ${{ runner.os }}- - name: Use Node.js 18 - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: node-version: "18" - name: Install dependencies