Skip to content

Commit 9f5ac4d

Browse files
authored
ci: publish main commit tag to ghcr.io/coder/coder-preview (#8897)
* wip * push new tag and delete old tag * prune by filtering * fix permission * fix filter * keep last 2 versions * use first 7 characters of sha for tag * do not use gh cli * test * typo * use gh cli again * reduce days to 3 * fixup * typo * keep-last 5 * ready to merge * retain tags from last 7 days * test * ready
1 parent 9fb18f3 commit 9f5ac4d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@ jobs:
701701
runs-on: ${{ github.repository_owner == 'coder' && 'buildjet-8vcpu-ubuntu-2204' || 'ubuntu-latest' }}
702702
env:
703703
DOCKER_CLI_EXPERIMENTAL: "enabled"
704+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
704705
steps:
705706
- name: Checkout
706707
uses: actions/checkout@v3
@@ -724,6 +725,7 @@ jobs:
724725
password: ${{ secrets.GITHUB_TOKEN }}
725726

726727
- name: Build and push Linux amd64 Docker image
728+
id: build_and_push
727729
run: |
728730
set -euxo pipefail
729731
go mod download
@@ -738,3 +740,21 @@ jobs:
738740
--version $version \
739741
--push \
740742
build/coder_linux_amd64
743+
744+
# Get commit sha to be used as package tag
745+
new_package_tag=$(gh api repos/coder/coder/commits/main | jq -r '.sha[0:7]')
746+
747+
# Tag image with new package tag and push
748+
docker tag ghcr.io/coder/coder-preview:main ghcr.io/coder/coder-preview:main-$new_package_tag
749+
docker push ghcr.io/coder/coder-preview:main-$new_package_tag
750+
751+
- name: Prune old images
752+
uses: vlaurin/action-ghcr-prune@v0.5.0
753+
with:
754+
token: ${{ secrets.GITHUB_TOKEN }}
755+
organization: coder
756+
container: coder-preview
757+
keep-younger-than: 7 # days
758+
keep-tags-regexes: ^pr
759+
prune-tags-regexes: ^main-
760+
prune-untagged: true

0 commit comments

Comments
 (0)