-
Notifications
You must be signed in to change notification settings - Fork 354
90 lines (79 loc) · 3.09 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
on:
- push
- workflow_dispatch
jobs:
build:
runs-on: ubuntu-latest-16-cores
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log into Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Log into GitHub Packages
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' }}
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build (latest)
if: ${{ github.ref == 'refs/heads/main' }}
run: |
export VCS_REF=$(git rev-parse HEAD)
npm install -g @devcontainers/cli
devcontainer build --workspace-folder . --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 (develop)
if: ${{ github.ref == 'refs/heads/develop' }}
run: |
export VCS_REF=$(git rev-parse HEAD)
npm install -g @devcontainers/cli
devcontainer build --workspace-folder . --image-name cs50/codespace:${{ github.sha }} --image-name cs50/codespace:develop
- name: Push (develop) to GitHub Packages
if: ${{ github.ref == 'refs/heads/develop' }}
run: |
docker tag cs50/codespace:${{ github.sha }} ghcr.io/cs50/codespace:develop
docker push ghcr.io/cs50/codespace:develop
- name: Push to Docker Hub (develop)
if: ${{ github.ref == 'refs/heads/develop' }}
run: |
docker push cs50/codespace:${{ github.sha }}
docker push cs50/codespace:develop
- name: Tag main as latest
if: ${{ github.ref == 'refs/heads/main' }}
uses: actions/github-script@v6
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
})
}