Skip to content

Commit 1d19925

Browse files
authored
Continuous deployment (#16)
Created deploy script to automatically deploy new versions to GitHub packages using Docker. This resolves #4 I changed a bit my formula and cleaned up the code quite a lot. The publish method has been merged into one (originally it was one to tag and one to deploy, but using `gh` I could minimize the footprint).
1 parent 36e3490 commit 1d19925

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

.github/workflows/release.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Publish package to GitHub Packages
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
8+
env:
9+
IMAGE_NAME: action
10+
REGISTRY: ghcr.io
11+
12+
jobs:
13+
test-image:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/[email protected]
17+
- name: Check that the image builds
18+
run: docker build . --file Dockerfile
19+
validate-action:
20+
runs-on: ubuntu-latest
21+
if: github.event_name == 'pull_request'
22+
steps:
23+
- uses: actions/[email protected]
24+
# This checks that .github/workflows/review-bot.yml is pointing towards the main branch
25+
# as, during development, we change this to use the code from the test branch and
26+
# we may forget to set it back to main
27+
- name: Validate that action points to main branch
28+
run: |
29+
BRANCH=$(yq '.jobs.set-auto-merge.steps[0].uses' $FILE_NAME | cut -d "@" -f2)
30+
# If the branch is not the main branch
31+
if [ "$BRANCH" != "$GITHUB_BASE_REF" ]; then
32+
echo "Action points to $BRANCH. It has to point to $GITHUB_BASE_REF instead!"
33+
exit 1
34+
else
35+
echo "Action is correctly pointing to $GITHUB_BASE_REF"
36+
fi
37+
env:
38+
FILE_NAME: ".github/workflows/auto-merge-bot.yml"
39+
40+
compare-versions:
41+
runs-on: ubuntu-latest
42+
outputs:
43+
version: ${{ steps.verification.outputs.VERSION }}
44+
exists: ${{ steps.checkTag.outputs.exists }}
45+
steps:
46+
- uses: actions/[email protected]
47+
- name: Extract package.json version
48+
id: package_version
49+
run: echo "VERSION=$(jq '.version' -r package.json)" >> $GITHUB_OUTPUT
50+
# Compare that the versions contain the same name
51+
- name: Compare versions
52+
id: verification
53+
uses: Bullrich/compare-version-on-action@main
54+
with:
55+
version: ${{ steps.package_version.outputs.VERSION }}
56+
# Verifies if there is a tag with that version number
57+
- uses: mukunku/[email protected]
58+
if: steps.verification.outputs.VERSION
59+
id: checkTag
60+
with:
61+
tag: v${{ steps.package_version.outputs.VERSION }}
62+
63+
publish:
64+
if: github.event_name == 'push' && needs.compare-versions.outputs.exists == 'false'
65+
needs: [test-image, compare-versions]
66+
runs-on: ubuntu-latest
67+
permissions:
68+
contents: write
69+
packages: write
70+
steps:
71+
- uses: actions/[email protected]
72+
- name: Tag version and create release
73+
run: gh release create $VERSION --generate-notes
74+
env:
75+
VERSION: ${{ needs.compare-versions.outputs.version }}
76+
GH_TOKEN: ${{ github.token }}
77+
- name: Log in to the Container registry
78+
uses: docker/login-action@v3
79+
with:
80+
registry: ${{ env.REGISTRY }}
81+
username: ${{ github.actor }}
82+
password: ${{ secrets.GITHUB_TOKEN }}
83+
- name: Extract metadata (tags, labels) for Docker
84+
id: meta
85+
uses: docker/metadata-action@v5
86+
with:
87+
images: ${{ env.REGISTRY }}/${{ github.repository }}/${{ env.IMAGE_NAME }}
88+
tags: ${{ needs.compare-versions.outputs.version }}
89+
- uses: actions/checkout@v3
90+
- name: Build and push Docker image
91+
uses: docker/build-push-action@v5
92+
with:
93+
context: .
94+
push: true
95+
tags: ${{ steps.meta.outputs.tags }}
96+
labels: ${{ steps.meta.outputs.labels }}

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,14 @@ The bot can only be triggered by the author of the PR or by users who *publicly*
6161
By publicly, I refer to the members of an organization which can be seen by external parties. If you are not sure if you are part of an organization, simply open https://github.com/orgs/**your_organization**/people in a private window. If you don’t see your name there, you are not a public member.
6262

6363
Find related docs here: [Publicizing or hiding organization membership](https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-personal-account-on-github/managing-your-membership-in-organizations/publicizing-or-hiding-organization-membership).
64+
65+
## Deployment
66+
67+
To deploy a new version you need to update two files:
68+
- [`package.json`](./package.json): Update the version number.
69+
- [`action.yml`](./action.yml): Update the image number in `runs.image`.
70+
**Important**: Both versions must have the same number.
71+
72+
When a commit is pushed to the main branch and the versions have changed, the system will automatically tag the commit and release a new package with such version.
73+
74+
You can find all the available versions in the [release section](./releases).

0 commit comments

Comments
 (0)