Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit e48e7f0

Browse files
add publish workflow
1 parent f55b951 commit e48e7f0

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

.github/workflows/publish.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: publish
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
jobs:
9+
10+
publish:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: checkout
15+
uses: actions/[email protected]
16+
17+
- name: version
18+
run: |
19+
# Tagged release
20+
if [[ ${{ github.ref }} == refs/tags/* ]]; then
21+
# Strip git ref prefix from $VERSION
22+
TAGNAME=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
23+
# Strip "v" prefix from tag name
24+
VERSION=$(echo $TAGNAME | sed -e 's/^v//')
25+
else
26+
VERSION=${{ github.sha }}
27+
fi
28+
29+
echo "VERSION=$VERSION" >> $GITHUB_ENV
30+
echo "GITHUB_REF=$GITHUB_REF" >> $GITHUB_ENV
31+
32+
# write .env to export ENV VARIABLES as artifacts for use in other workflow_run runs
33+
echo "PUBLISH_VERSION=$VERSION" >> .env
34+
echo "PUBLISH_GITHUB_REF=$GITHUB_REF" >> .env
35+
36+
echo "Version: $VERSION"
37+
38+
export DOCKER_BUILDKIT=1
39+
40+
- name: publish
41+
run: |
42+
VERSION="${{ env.VERSION }}"
43+
44+
echo ${{ secrets.GITHUB_TOKEN }} | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
45+
46+
# build and run the docker images
47+
docker-compose -f docker-compose.build.yml up --no-start
48+
49+
# get all built IDs
50+
IMAGE_IDs=$(docker-compose -f docker-compose.build.yml images -q)
51+
52+
echo "IMAGE_IDs: $IMAGE_IDs"
53+
54+
while read -r IMAGE_ID; do
55+
56+
echo "IMAGE_ID: $IMAGE_ID"
57+
# get the name label
58+
NAME=$(basename ${{ github.repository }}).$(docker inspect --format '{{ index .Config.Labels.name }}' $IMAGE_ID)
59+
PUSH="docker.pkg.github.com/${{ github.repository }}/$NAME:$VERSION"
60+
61+
# tag and push
62+
docker tag $IMAGE_ID $PUSH
63+
docker push $PUSH
64+
65+
done <<< "$IMAGE_IDs"
66+
67+
# Upload reference as artifact to pass to deploy
68+
- name: upload .env
69+
uses: actions/upload-artifact@v2
70+
with:
71+
name: env
72+
path: .env

0 commit comments

Comments
 (0)