-
Notifications
You must be signed in to change notification settings - Fork 353
116 lines (101 loc) · 4.51 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
on:
- push
- workflow_dispatch
jobs:
build:
runs-on: ubuntu-latest-64-cores
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.11'
- 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
})
}