Skip to content

Commit 231e316

Browse files
committed
Automate release process
1 parent 4590c3a commit 231e316

File tree

9 files changed

+125
-22
lines changed

9 files changed

+125
-22
lines changed

.github/workflows/ci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
- run: ./ci/steps/release-static.sh
8282
env:
8383
# Otherwise we get rate limited when fetching the ripgrep binary.
84-
GITHUB_TOKEN: ${{ secrets.github_token }}
84+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8585
- name: Upload release artifacts
8686
uses: actions/upload-artifact@v2
8787
with:

.github/workflows/publish.yaml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: publish
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
npm:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v1
12+
- name: Run ./ci/steps/publish-npm.sh
13+
uses: ./ci/container
14+
with:
15+
args: ./ci/steps/publish-npm.sh
16+
env:
17+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
18+
19+
docker-amd64:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v1
23+
- name: Run ./ci/steps/publish-docker.sh
24+
uses: ./ci/container
25+
with:
26+
args: ./ci/steps/publish-docker.sh
27+
env:
28+
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
29+
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
30+
31+
docker-arm64:
32+
runs-on: ubuntu-arm64-latest
33+
steps:
34+
- uses: actions/checkout@v1
35+
- name: Run ./ci/steps/publish-docker.sh
36+
uses: ./ci/container
37+
with:
38+
args: ./ci/steps/publish-docker.sh
39+
env:
40+
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
41+
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}

ci/README.md

+16-11
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@ Any file and directory added into this tree should be documented here.
88

99
## Publishing a release
1010

11-
1. Change the version of code-server in `package.json` and push this commit.
12-
1. CI will run and generate an NPM package and release packages that you can download
13-
as artifacts on Github Actions.
14-
1. Create a new draft release with the built release packages.
15-
1. Run some basic sanity tests on one of the released packages.
16-
1. Publish.
17-
1. Download the built npm package and publish it.
18-
1. Place the debian releases into `./release-packages` and then push the docker
19-
image with `./ci/release-container/push.sh`.
20-
1. This will need to be ran on an ARM64 instance as well.
21-
1. At some point we need to automate this.
11+
1. Update the version of code-server in `package.json` and push a commit
12+
1. CI will run and generate the `npm-package` and `release-packages` artifacts on the GH actions workflow
13+
1. Create a new draft release and attach all the files in `release-packages`
14+
1. Run some basic sanity tests on one of the released packages
15+
1. Publish the release
16+
1. CI will automatically grab the artifacts and then
17+
1. Publish the NPM package.
18+
1. Publish the AMD64 docker image.
19+
1. Publish the ARM64 docker image.
2220

2321
## dev
2422

@@ -95,3 +93,10 @@ Just helps avoid clobbering .travis.yml.
9593
- Generates the npm package at `./release`
9694
- [./steps/static-release.sh](./steps/static-release.sh)
9795
- Takes the output of the previous script and generates a static release and packages
96+
- [./steps/lib.sh](./steps/lib.sh)
97+
- Contains helpers to download artifacts from github actions workflow runs
98+
- [./steps/publish-npm.sh](./steps/publish-npm.sh)
99+
- Grabs the `npm-package` release artifact for the current commit and publishes it on NPM
100+
- [./steps/publish-docker.sh](./steps/publish-docker.sh)
101+
- Grabs the `release-packages` release artifact for the current commit and builds a docker
102+
image with it and publishes that onto docker hub

ci/container/Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ RUN apt-get update
66
RUN apt-get install -y curl gnupg
77

88
# Installs node.
9-
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
9+
RUN curl -sSL https://deb.nodesource.com/setup_14.x | bash - && \
1010
apt-get install -y nodejs
1111

1212
# Installs yarn.
13-
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
13+
RUN curl -sSL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
1414
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
1515
apt-get update && apt-get install -y yarn
1616

@@ -27,14 +27,14 @@ RUN apt-get install -y gettext-base
2727
RUN apt-get install -y jq git rsync
2828

2929
# Installs shellcheck.
30-
RUN curl -L https://github.com/koalaman/shellcheck/releases/download/v0.7.1/shellcheck-v0.7.1.linux.$(uname -m).tar.xz | \
30+
RUN curl -sSL https://github.com/koalaman/shellcheck/releases/download/v0.7.1/shellcheck-v0.7.1.linux.$(uname -m).tar.xz | \
3131
tar -xJ && \
3232
mv shellcheck*/shellcheck /usr/local/bin && \
3333
rm -R shellcheck*
3434

3535
# Install Go dependencies
3636
RUN ARCH="$(dpkg --print-architecture)" && \
37-
curl "https://dl.google.com/go/go1.14.2.linux-$ARCH.tar.gz" | tar -C /usr/local -xz
37+
curl -sSL "https://dl.google.com/go/go1.14.2.linux-$ARCH.tar.gz" | tar -C /usr/local -xz
3838
ENV PATH=/usr/local/go/bin:/root/go/bin:$PATH
3939
ENV GO111MODULE=on
4040
RUN go get mvdan.cc/sh/v3/cmd/shfmt

ci/release-container/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ RUN adduser --gecos '' --disabled-password coder && \
2828
echo "coder ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/nopasswd
2929

3030
RUN ARCH="$(dpkg --print-architecture)" && \
31-
curl -L "https://github.com/boxboat/fixuid/releases/download/v0.4.1/fixuid-0.4.1-linux-$ARCH.tar.gz" | tar -C /usr/local/bin -xzf - && \
31+
curl -sSL "https://github.com/boxboat/fixuid/releases/download/v0.4.1/fixuid-0.4.1-linux-$ARCH.tar.gz" | tar -C /usr/local/bin -xzf - && \
3232
chown root:root /usr/local/bin/fixuid && \
3333
chmod 4755 /usr/local/bin/fixuid && \
3434
mkdir -p /etc/fixuid && \
3535
printf "user: coder\ngroup: coder\n" > /etc/fixuid/config.yml
3636

3737
COPY release-packages/code-server*.deb /tmp/
38-
RUN dpkg -i /tmp/code-server*.deb && rm /tmp/code-server*.deb
38+
RUN dpkg -i /tmp/code-server*-$(dpkg --print-architecture).deb && rm /tmp/code-server*.deb
3939

4040
EXPOSE 8080
4141
USER coder

ci/release-container/push.sh

-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ main() {
77
source ./ci/lib.sh
88
VERSION="$(pkg_json_version)"
99

10-
if [[ ${CI-} ]]; then
11-
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
12-
fi
13-
1410
imageTag="codercom/code-server:$VERSION"
1511
if [[ $(arch) == "arm64" ]]; then
1612
imageTag+="-arm64"

ci/steps/lib.sh

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
source ./ci/lib.sh
3+
4+
# Grabs the most recent ci.yaml github workflow run that was successful and triggered from the same commit being pushd.
5+
# This will contain the artifacts we want.
6+
# https://developer.github.com/v3/actions/workflow-runs/#list-workflow-runs
7+
get_artifacts_url() {
8+
curl -sSL 'https://api.github.com/repos/cdr/code-server/actions/workflows/ci.yaml/runs?status=success&event=push' | jq -r ".workflow_runs[] | select(.head_sha == \"$(git rev-parse HEAD)\") | .artifacts_url" | head -n 1
9+
}
10+
11+
# Grabs the artifact's download url.
12+
# https://developer.github.com/v3/actions/artifacts/#list-workflow-run-artifacts
13+
get_artifact_url() {
14+
local artifact_name="$1"
15+
curl -sSL "$(get_artifacts_url)" | jq -r ".artifacts[] | select(.name == \"$artifact_name\") | .archive_download_url" | head -n 1
16+
}
17+
18+
# Uses the above two functions to download a artifact into a directory.
19+
download_artifact() {
20+
local artifact_name="$1"
21+
local dst="$2"
22+
23+
local tmp_file
24+
tmp_file="$(mktemp)"
25+
26+
curl -sSL "$(get_artifact_url "$artifact_name")" > "$tmp_file"
27+
unzip -o "$tmp_file" -d "$dst"
28+
rm "$tmp_file"
29+
}

ci/steps/publish-docker.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
main() {
5+
cd "$(dirname "$0")/../.."
6+
source ./ci/steps/lib.sh
7+
8+
if [[ ${CI-} ]]; then
9+
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
10+
fi
11+
12+
download_artifact release-packages ./release-packages
13+
./ci/release-container/push.sh
14+
}
15+
16+
main "$@"

ci/steps/publish-npm.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
main() {
5+
cd "$(dirname "$0")/../.."
6+
source ./ci/steps/lib.sh
7+
8+
if [[ ${CI-} ]]; then
9+
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
10+
fi
11+
12+
download_artifact npm-package ./release
13+
yarn publish --non-interactive release
14+
}
15+
16+
main "$@"

0 commit comments

Comments
 (0)