ci: split container push steps to separate job and add deploy tag
authorChristian Marangi <ansuelsmth@gmail.com>
Tue, 14 Nov 2023 13:53:12 +0000 (14:53 +0100)
committerPetr Štetiar <ynezz@true.cz>
Tue, 14 Nov 2023 17:25:45 +0000 (18:25 +0100)
Split container push related steps to separate jobs and add deploy tag.

This is to better organize the workflow and drop additional checks for
single steps moving them to the single job.
Also we use a feature of github to better track changes deployed to our
buildbot.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
.github/workflows/build-push.yml

index 07945bfe93d8c631c4c54acf4a0535161ba4099b..199b739a6be4db261e4b8d763157c655450cb085 100644 (file)
@@ -43,8 +43,8 @@ jobs:
       - name: Stylecheck with black
         run: black phase1/master.cfg
 
-  build-test-push:
-    name: Build, test and push containers
+  build-test:
+    name: Build and Test container
     runs-on: ubuntu-latest
     needs: test-lint
 
@@ -86,16 +86,39 @@ jobs:
           docker logs test-${{ matrix.container_flavor }} | tee ${{ matrix.container_flavor }}.log
           grep "${{ matrix.container_verify_string }}" ${{ matrix.container_flavor }}.log
 
+  deploy:
+    name: Push Container
+    if: github.event_name != 'pull_request' || github.repository_owner != 'openwrt'
+    runs-on: ubuntu-latest
+    needs: build-test
+
+    environment: production
+
+    permissions:
+      packages: write
+
+    strategy:
+      matrix:
+        container_flavor:
+          - master
+          - worker
+
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v3
+
+      - name: Environment variables
+        run: |
+          echo "GIT_SHA_SHORT=${GITHUB_SHA::${{ env.GITHUB_SHA_LEN }}}" >> $GITHUB_ENV
+
       - name: Docker meta
         id: meta
-        if: github.event_name != 'pull_request' || github.repository_owner != 'openwrt'
         uses: docker/metadata-action@v4
         with:
           images: name=ghcr.io/${{ github.repository }}/build${{ matrix.container_flavor }}-v${{ env.BUILDBOT_VERSION }}
 
       - name: Login to GitHub Container Registry
         uses: docker/login-action@v2
-        if: github.event_name != 'pull_request' || github.repository_owner != 'openwrt'
         with:
           registry: ghcr.io
           username: ${{ github.actor }}
@@ -103,7 +126,6 @@ jobs:
 
       - name: Build container again and push it
         uses: docker/build-push-action@v4
-        if: github.event_name != 'pull_request' || github.repository_owner != 'openwrt'
         with:
           push: true
           tags: ${{ steps.meta.outputs.tags }}