Skip to content

Commit b3d0fec

Browse files
committed
feat: moved action to use GitHub Package Registry (#54)
Updated the project to store an already built image in the GitHub Package Registry. This PR brings 3 changes: - It creates a new release CI flow. - It modifies the Docker image to be a multi step image. - It changes the action definition file (`action.yml`) to use an image from the registry. ## The CI The new CI workflow does the following: - Checks that the Docker image can be built. - Checks that the version for the package and the docker image are the same - If the version in the `package.json` changed: - Tag the commit with the new version - Generate a new release (with a changelog) - Builds and publishes the docker image using the new tag ## The Dockerimage As the image is being stored, I modified it to actually use a second slim version with the compiled code so it is smaller (and gets downloaded faster).
1 parent ab74b59 commit b3d0fec

File tree

6 files changed

+136
-7
lines changed

6 files changed

+136
-7
lines changed

.github/workflows/publish.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: Publish package to GitHub Packages
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
8+
env:
9+
IMAGE_NAME: action
10+
11+
jobs:
12+
test-image:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/[email protected]
16+
- name: Check that the image builds
17+
run: docker build . --file Dockerfile
18+
19+
test-versions:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/[email protected]
23+
- name: Extract package.json version
24+
id: package_version
25+
run: echo "VERSION=$(jq '.version' -r package.json)" >> $GITHUB_OUTPUT
26+
- name: Extract action.yml version
27+
uses: mikefarah/yq@master
28+
id: action_image
29+
with:
30+
cmd: yq '.runs.image' 'action.yml'
31+
- name: Parse action.yml version
32+
id: action_version
33+
run: |
34+
echo "IMAGE_VERSION=$(echo $IMAGE_URL | cut -d: -f3)" >> $GITHUB_OUTPUT
35+
env:
36+
IMAGE_URL: ${{ steps.action_image.outputs.result }}
37+
- name: Compare versions
38+
run: |
39+
echo "Verifying that $IMAGE_VERSION from action.yml is the same as $PACKAGE_VERSION from package.json"
40+
[[ $IMAGE_VERSION == $PACKAGE_VERSION ]]
41+
env:
42+
IMAGE_VERSION: ${{ steps.action_version.outputs.IMAGE_VERSION }}
43+
PACKAGE_VERSION: ${{ steps.package_version.outputs.VERSION }}
44+
45+
tag:
46+
if: github.event_name == 'push'
47+
needs: [test-image, test-versions]
48+
runs-on: ubuntu-latest
49+
permissions:
50+
contents: write
51+
outputs:
52+
tagcreated: ${{ steps.autotag.outputs.tagcreated }}
53+
tagname: ${{ steps.autotag.outputs.tagname }}
54+
steps:
55+
- uses: actions/[email protected]
56+
with:
57+
fetch-depth: 0
58+
- uses: butlerlogic/action-autotag@stable
59+
id: autotag
60+
with:
61+
head_branch: master
62+
tag_prefix: "v"
63+
env:
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
- name: Changelog
66+
uses: Bullrich/[email protected]
67+
id: Changelog
68+
env:
69+
REPO: ${{ github.repository }}
70+
- name: Create Release
71+
if: steps.autotag.outputs.tagname != ''
72+
uses: actions/create-release@latest
73+
env:
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+
with:
76+
tag_name: ${{ steps.autotag.outputs.tagname }}
77+
release_name: Release ${{ steps.autotag.outputs.tagname }}
78+
body: |
79+
${{ steps.Changelog.outputs.changelog }}
80+
81+
publish:
82+
runs-on: ubuntu-latest
83+
permissions:
84+
packages: write
85+
needs: [tag]
86+
if: needs.tag.outputs.tagname != ''
87+
steps:
88+
- uses: actions/checkout@v3
89+
- name: Build image
90+
run: docker build . --file Dockerfile --tag $IMAGE_NAME
91+
- name: Log into registry
92+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
93+
- name: Push image
94+
run: |
95+
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
96+
97+
# Change all uppercase to lowercase
98+
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
99+
100+
# Strip git ref prefix from version
101+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
102+
103+
# Strip "v" prefix from tag name
104+
[[ ! -z $TAG ]] && VERSION=$(echo $TAG | sed -e 's/^v//')
105+
106+
# Use Docker `latest` tag convention
107+
[ "$VERSION" == "main" ] && VERSION=latest
108+
109+
echo IMAGE_ID=$IMAGE_ID
110+
echo VERSION=$VERSION
111+
112+
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
113+
docker push $IMAGE_ID:$VERSION
114+
env:
115+
TAG: ${{ needs.tag.outputs.tagname }}

Dockerfile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
FROM node:18
1+
FROM node:18 as Builder
2+
3+
WORKDIR /action
24

35
COPY package.json yarn.lock ./
46

@@ -8,4 +10,8 @@ COPY . .
810

911
RUN yarn build
1012

11-
CMD ["yarn", "start"]
13+
FROM node:18-slim
14+
15+
COPY --from=Builder /action/dist /action
16+
17+
ENTRYPOINT ["node", "/action/index.js"]

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
# Introduction
33

4+
![Publish](https://github.com/paritytech/github-issue-sync/actions/workflows/publish.yml/badge.svg?branch=master)
5+
46
This project enables syncing GitHub Issues to a [GitHub Project](https://docs.github.com/en/issues/planning-and-tracking-with-projects/learning-about-projects/about-projects).
57

68
## Why is this necessary?

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ inputs:
2929
type: string
3030
runs:
3131
using: 'docker'
32-
image: 'Dockerfile'
32+
image: 'docker://ghcr.io/paritytech/github-issue-sync/action:0.3.1'

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"name": "github-issue-sync",
3-
"version": "0.0.1",
3+
"version": "0.3.1",
44
"description": "Synchronize issues to GitHub Project boards",
55
"author": "Parity <[email protected]> (https://parity.io)",
66
"repository": {
77
"type": "git",
88
"url": "git+https://github.com/paritytech/github-issue-sync.git"
99
},
1010
"license": "Apache-2.0",
11-
"main": "dist/main.js",
11+
"main": "dist/index.js",
1212
"scripts": {
13-
"build": "tsc",
14-
"start": "node --experimental-modules dist/main.js",
13+
"build": "ncc build src/main.ts",
14+
"start": "node --experimental-modules dist/index.js",
1515
"test": "jest",
1616
"typecheck": "tsc --noEmit",
1717
"fix:eslint": "eslint --fix",
@@ -29,6 +29,7 @@
2929
"devDependencies": {
3030
"@octokit/graphql-schema": "^12.41.1",
3131
"@types/jest": "^29.2.6",
32+
"@vercel/ncc": "^0.36.1",
3233
"jest": "^29.3.1",
3334
"jest-mock-extended": "^3.0.1",
3435
"opstooling-js-style": "https://github.com/paritytech/opstooling-js-style#c298d0f732d93712e4397fd53baa3317a3022c8c",

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,11 @@
10321032
"@typescript-eslint/types" "5.48.1"
10331033
eslint-visitor-keys "^3.3.0"
10341034

1035+
"@vercel/ncc@^0.36.1":
1036+
version "0.36.1"
1037+
resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.36.1.tgz#d4c01fdbbe909d128d1bf11c7f8b5431654c5b95"
1038+
integrity sha512-S4cL7Taa9yb5qbv+6wLgiKVZ03Qfkc4jGRuiUQMQ8HGBD5pcNRnHeYM33zBvJE4/zJGjJJ8GScB+WmTsn9mORw==
1039+
10351040
acorn-jsx@^5.3.2:
10361041
version "5.3.2"
10371042
resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.2.tgz#7ed5bb55908b3b2f1bc55c6af1653bada7f07937"

0 commit comments

Comments
 (0)