use gh cli to force codespace full rebuild #1231
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
- push | |
- workflow_dispatch | |
jobs: | |
build: | |
runs-on: ubuntu-2404-64-cores-amd | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log into Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Log into GitHub Packages | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Setup Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
- name: Only use `build` and `features`, if any, from devcontainer.json | |
run: | | |
pip3 install jsmin | |
python3 -c "import jsmin, json; f = open('devcontainer.json', 'r'); data = json.loads(jsmin.jsmin(f.read())); o = {}; o['build']=data['build']; o['features']=data.get('features', []); o['remoteEnv']=data['remoteEnv']; f.close(); f = open('devcontainer.json', 'w'); f.write(json.dumps(o, indent=4)); f.close()" | |
- name: Build (latest) | |
if: ${{ github.ref == 'refs/heads/main' }} | |
run: | | |
export TAG=amd64 | |
export VCS_REF=$(git rev-parse HEAD) | |
npm install -g @devcontainers/cli | |
devcontainer build --workspace-folder . --config devcontainer.json --image-name cs50/codespace:${{ github.sha }} --image-name cs50/codespace:latest | |
- name: Push (latest) to GitHub Packages | |
if: ${{ github.ref == 'refs/heads/main' }} | |
run: | | |
docker tag cs50/codespace:${{ github.sha }} ghcr.io/cs50/codespace:${{ github.sha }} | |
docker tag cs50/codespace:latest ghcr.io/cs50/codespace:latest | |
docker push ghcr.io/cs50/codespace:${{ github.sha }} | |
docker push ghcr.io/cs50/codespace:latest | |
- name: Push to Docker Hub (latest) | |
if: ${{ github.ref == 'refs/heads/main' }} | |
run: | | |
docker push cs50/codespace:${{ github.sha }} | |
docker push cs50/codespace:latest | |
- name: Build (canary) | |
if: ${{ github.ref == 'refs/heads/canary' }} | |
run: | | |
export TAG=canary | |
export VCS_REF=$(git rev-parse HEAD) | |
npm install -g @devcontainers/cli | |
devcontainer build --workspace-folder . --config devcontainer.json --image-name cs50/codespace:${{ github.sha }} --image-name cs50/codespace:${{ github.ref_name }} | |
- name: Build (${{ github.ref_name}}) | |
if: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/canary' }} | |
run: | | |
export TAG=amd64 | |
export VCS_REF=$(git rev-parse HEAD) | |
npm install -g @devcontainers/cli | |
devcontainer build --workspace-folder . --config devcontainer.json --image-name cs50/codespace:${{ github.sha }} --image-name cs50/codespace:${{ github.ref_name }} | |
- name: Squash (${{ github.ref_name }}) | |
if: ${{ github.ref != 'refs/heads/main' }} | |
run: | | |
pip3 install docker-squash | |
docker-squash --tag cs50/codespace:${{ github.ref_name }} cs50/codespace:${{ github.ref_name }} | |
- name: Push (${{ github.ref_name }}) to GitHub Packages | |
if: ${{ github.ref != 'refs/heads/main' }} | |
run: | | |
docker tag cs50/codespace:${{ github.ref_name }} ghcr.io/cs50/codespace:${{ github.ref_name }} | |
docker push ghcr.io/cs50/codespace:${{ github.ref_name }} | |
- name: Push to Docker Hub (${{ github.ref_name }}) | |
if: ${{ github.ref != 'refs/heads/main' }} | |
run: | | |
docker tag cs50/codespace:${{ github.ref_name }} cs50/codespace:${{ github.sha }} | |
docker push cs50/codespace:${{ github.ref_name }} | |
docker push cs50/codespace:${{ github.sha }} | |
- name: Tag main as latest | |
if: ${{ github.ref == 'refs/heads/main' }} | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ github.token }} | |
script: | | |
try { | |
await github.rest.git.updateRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: "tags/latest", | |
sha: context.sha, | |
force: true | |
}) | |
} catch (e) { | |
await github.rest.git.createRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: "refs/tags/latest", | |
sha: context.sha | |
}) | |
} |