Skip to content

Commit 1aa6194

Browse files
authored
fix: publish containers after automated release (#112)
The publish workflow is supposed to run whenever a new tag is pushed, which did not happen. Also release triggers did not work. I tried everything which came to my mind in https://github.com/lurtz/conventional_commits_test/blob/main/.github/workflows/publish.yaml By merging the workflows we avoid the hazzle of having to call another workflow.
1 parent 3e94ddf commit 1aa6194

2 files changed

Lines changed: 48 additions & 52 deletions

File tree

.github/workflows/publish.yaml renamed to .github/workflows/release-and-publish.yaml

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,49 @@
1010
#
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
13-
name: Validate & Publish DevContainer
14-
description: This workflow is checking that for releases, updates do not break stuff and publishes the released container.
13+
name: DevContainer Release & Validate & Publish
14+
description: This workflow creates a semantic version release when main changed since the last release tag. Then it checks that for releases, updates do not break stuff and publishes the released container.
1515
on:
16-
push:
17-
tags:
18-
- v[0-9]+.[0-9]+.[0-9]+
16+
schedule:
17+
- cron: '0 0 * * 1'
18+
workflow_dispatch:
19+
permissions:
20+
contents: read # for checkout
1921
jobs:
22+
release:
23+
if: github.ref == 'refs/heads/main'
24+
permissions:
25+
contents: write # to be able to publish a GitHub release
26+
issues: write # to be able to comment on released issues
27+
pull-requests: write # to be able to comment on released pull requests
28+
name: release
29+
runs-on: ubuntu-latest
30+
outputs:
31+
tag_name: ${{ steps.run-semantic-release.outputs.tag_name }}
32+
container:
33+
image: mcr.microsoft.com/devcontainers/javascript-node:4-24
34+
steps:
35+
- uses: actions/checkout@v6
36+
with:
37+
fetch-depth: 0
38+
fetch-tags: true
39+
# this should have been done by the checkout action, but it doesn't work in a container, see https://github.com/actions/checkout/issues/766
40+
- run: git config --global --add safe.directory $PWD
41+
# pinned version updated automatically by Dependabot.
42+
# details at https://semantic-release.gitbook.io/semantic-release/usage/installation#global-installation
43+
- name: npx semantic-release
44+
id: run-semantic-release
45+
run: |
46+
set -eux pipefail
47+
npx semantic-release@25.0.1 >> /tmp/semantic-release.log 2>&1 || (cat /tmp/semantic-release.log && exit 1)
48+
cat /tmp/semantic-release.log
49+
tag_name=$(grep "Created tag" /tmp/semantic-release.log | sed -E 's/.*Created tag (.*)/\1/')
50+
echo "tag_name=$tag_name" >> $GITHUB_OUTPUT
51+
env:
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2053
build:
54+
needs: [release]
55+
if: needs.release.outputs.tag_name != ''
2156
strategy:
2257
matrix:
2358
os: [arm64, amd64]
@@ -38,6 +73,8 @@ jobs:
3873
- uses: eclipse-score/more-disk-space@v1
3974
- name: Checkout (GitHub)
4075
uses: actions/checkout@v6
76+
with:
77+
ref: ${{ needs.release.outputs.tag_name }}
4178
- name: Login to GitHub Container Registry
4279
uses: docker/login-action@v4
4380
with:
@@ -61,7 +98,7 @@ jobs:
6198
./scripts/create_builder.sh
6299
63100
# Build
64-
./scripts/build.sh --${{ matrix.os }} "${{ github.ref_name }}" "latest"
101+
./scripts/build.sh --${{ matrix.os }} "${{ needs.release.outputs.tag_name }}" "latest"
65102
66103
# Test
67104
./scripts/test.sh
@@ -71,10 +108,10 @@ jobs:
71108
# Instead, we use the publish script which pushes the correct container (residing in src/s-core-devcontainer).
72109
# manually login to ghcr.io for publishing
73110
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
74-
./scripts/publish.sh --${{ matrix.os }} "${{ github.ref_name }}" "latest"
111+
./scripts/publish.sh --${{ matrix.os }} "${{ needs.release.outputs.tag_name }}" "latest"
75112
merge:
76113
name: Merge Labels
77-
needs: [build]
114+
needs: [build, release]
78115
runs-on: ubuntu-24.04
79116
permissions:
80117
contents: read
@@ -84,6 +121,8 @@ jobs:
84121
- uses: eclipse-score/more-disk-space@v1
85122
- name: Checkout (GitHub)
86123
uses: actions/checkout@v6
124+
with:
125+
ref: ${{ needs.release.outputs.tag_name }}
87126
- name: Login to GitHub Container Registry
88127
uses: docker/login-action@v4
89128
with:
@@ -105,4 +144,4 @@ jobs:
105144
# Instead, we use the publish script which pushes the correct container (residing in src/s-core-devcontainer).
106145
# manually login to ghcr.io for publishing
107146
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
108-
./scripts/merge.sh "${{ github.ref_name }}" "latest"
147+
./scripts/merge.sh "${{ needs.release.outputs.tag_name }}" "latest"

.github/workflows/release.yaml

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)