diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..cafd0c3 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,115 @@ +name: Publish package to GitHub Packages +on: + push: + branches: + - master + pull_request: + +env: + IMAGE_NAME: action + +jobs: + test-image: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3.3.0 + - name: Check that the image builds + run: docker build . --file Dockerfile + + test-versions: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3.3.0 + - name: Extract package.json version + id: package_version + run: echo "VERSION=$(jq '.version' -r package.json)" >> $GITHUB_OUTPUT + - name: Extract action.yml version + uses: mikefarah/yq@master + id: action_image + with: + cmd: yq '.runs.image' 'action.yml' + - name: Parse action.yml version + id: action_version + run: | + echo "IMAGE_VERSION=$(echo $IMAGE_URL | cut -d: -f3)" >> $GITHUB_OUTPUT + env: + IMAGE_URL: ${{ steps.action_image.outputs.result }} + - name: Compare versions + run: | + echo "Verifying that $IMAGE_VERSION from action.yml is the same as $PACKAGE_VERSION from package.json" + [[ $IMAGE_VERSION == $PACKAGE_VERSION ]] + env: + IMAGE_VERSION: ${{ steps.action_version.outputs.IMAGE_VERSION }} + PACKAGE_VERSION: ${{ steps.package_version.outputs.VERSION }} + + tag: + if: github.event_name == 'push' + needs: [test-image, test-versions] + runs-on: ubuntu-latest + permissions: + contents: write + outputs: + tagcreated: ${{ steps.autotag.outputs.tagcreated }} + tagname: ${{ steps.autotag.outputs.tagname }} + steps: + - uses: actions/checkout@v3.3.0 + with: + fetch-depth: 0 + - uses: butlerlogic/action-autotag@stable + id: autotag + with: + head_branch: master + tag_prefix: "v" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Changelog + uses: Bullrich/generate-release-changelog@2.0.2 + id: Changelog + env: + REPO: ${{ github.repository }} + - name: Create Release + if: steps.autotag.outputs.tagname != '' + uses: actions/create-release@latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.autotag.outputs.tagname }} + release_name: Release ${{ steps.autotag.outputs.tagname }} + body: | + ${{ steps.Changelog.outputs.changelog }} + + publish: + runs-on: ubuntu-latest + permissions: + packages: write + needs: [tag] + if: needs.tag.outputs.tagname != '' + steps: + - uses: actions/checkout@v3 + - name: Build image + run: docker build . --file Dockerfile --tag $IMAGE_NAME + - name: Log into registry + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin + - name: Push image + run: | + IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME + + # Change all uppercase to lowercase + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + + # Strip "v" prefix from tag name + [[ ! -z $TAG ]] && VERSION=$(echo $TAG | sed -e 's/^v//') + + # Use Docker `latest` tag convention + [ "$VERSION" == "main" ] && VERSION=latest + + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + + docker tag $IMAGE_NAME $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION + env: + TAG: ${{ needs.tag.outputs.tagname }} diff --git a/Dockerfile b/Dockerfile index fd253c0..b84e3cb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ -FROM node:18 +FROM node:18 as Builder + +WORKDIR /action COPY package.json yarn.lock ./ @@ -8,4 +10,8 @@ COPY . . RUN yarn build -CMD ["yarn", "start"] +FROM node:18-slim + +COPY --from=Builder /action/dist /action + +ENTRYPOINT ["node", "/action/index.js"] diff --git a/README.md b/README.md index 79717ce..b7c3ce8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # Introduction +![Publish](https://github.com/paritytech/github-issue-sync/actions/workflows/publish.yml/badge.svg?branch=master) + 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). ## Why is this necessary? diff --git a/action.yml b/action.yml index 59d2f7d..3aa2d86 100644 --- a/action.yml +++ b/action.yml @@ -29,4 +29,4 @@ inputs: type: string runs: using: 'docker' - image: 'Dockerfile' + image: 'docker://ghcr.io/paritytech/github-issue-sync/action:0.3.1' diff --git a/package.json b/package.json index 52c7ded..764bc5f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "github-issue-sync", - "version": "0.0.1", + "version": "0.3.1", "description": "Synchronize issues to GitHub Project boards", "author": "Parity (https://parity.io)", "repository": { @@ -8,10 +8,10 @@ "url": "git+https://github.com/paritytech/github-issue-sync.git" }, "license": "Apache-2.0", - "main": "dist/main.js", + "main": "dist/index.js", "scripts": { - "build": "tsc", - "start": "node --experimental-modules dist/main.js", + "build": "ncc build src/main.ts", + "start": "node --experimental-modules dist/index.js", "test": "jest", "typecheck": "tsc --noEmit", "fix:eslint": "eslint --fix", @@ -29,6 +29,7 @@ "devDependencies": { "@octokit/graphql-schema": "^12.41.1", "@types/jest": "^29.2.6", + "@vercel/ncc": "^0.36.1", "jest": "^29.3.1", "jest-mock-extended": "^3.0.1", "opstooling-js-style": "https://github.com/paritytech/opstooling-js-style#c298d0f732d93712e4397fd53baa3317a3022c8c", diff --git a/yarn.lock b/yarn.lock index a9c95a7..849c107 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1032,6 +1032,11 @@ "@typescript-eslint/types" "5.48.1" eslint-visitor-keys "^3.3.0" +"@vercel/ncc@^0.36.1": + version "0.36.1" + resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.36.1.tgz#d4c01fdbbe909d128d1bf11c7f8b5431654c5b95" + integrity sha512-S4cL7Taa9yb5qbv+6wLgiKVZ03Qfkc4jGRuiUQMQ8HGBD5pcNRnHeYM33zBvJE4/zJGjJJ8GScB+WmTsn9mORw== + acorn-jsx@^5.3.2: version "5.3.2" resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.2.tgz#7ed5bb55908b3b2f1bc55c6af1653bada7f07937"