|
1 | | -name: Publish Package to npmjs |
| 1 | +name: Publish Docker Image to GHCR |
| 2 | + |
2 | 3 | on: |
3 | 4 | push: |
4 | 5 | branches: |
5 | 6 | - next |
| 7 | + |
6 | 8 | jobs: |
7 | | - build: |
| 9 | + publish: |
8 | 10 | runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + packages: write |
| 13 | + contents: read |
| 14 | + |
9 | 15 | steps: |
10 | 16 | - uses: actions/checkout@v3 |
11 | | - # Setup .npmrc file to publish to npm |
12 | | - - uses: actions/setup-node@v3 |
13 | | - with: |
14 | | - node-version: '22.x' |
15 | | - registry-url: 'https://registry.npmjs.org' |
16 | 17 |
|
17 | | - - run: npm i --force && npm run build |
18 | | - - run: cp ./package.json ./dist && cp ./Readme.md ./dist/ && echo '//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}' > ./dist/.npmrc |
| 18 | + - name: Log in to GitHub Container Registry |
| 19 | + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin |
| 20 | + |
| 21 | + - name: Set up image name |
| 22 | + id: meta |
| 23 | + run: | |
| 24 | + IMAGE_NAME=ghcr.io/${{ github.repository_owner }}/$(basename ${{ github.repository }} | tr '[:upper:]' '[:lower:]') |
| 25 | + echo "image_name=$IMAGE_NAME" >> $GITHUB_OUTPUT |
| 26 | +
|
| 27 | + - name: Build Docker image |
| 28 | + run: | |
| 29 | + docker build -f fixture/Dockerfile.demo -t ${{ steps.meta.outputs.image_name }}:demo . |
19 | 30 |
|
20 | | - # resolve version |
21 | | - - run: | |
22 | | - set -x |
23 | | - BRANCH=${GITHUB_REF##*/} |
24 | | - PACKAGE=$(cat package.json | jq -r '.["name"]') |
25 | | - VERLOC=$(cat package.json | jq -r '.["version"]') |
26 | | - VERNPMRAW=$(curl -s https://registry.npmjs.org/$PACKAGE | jq -r '.["dist-tags"].'$BRANCH'') |
27 | | - BUILD_VERSION=0 |
28 | | - if [[ "$VERNPMRAW" == "null" ]]; then |
29 | | - VEROUT=$VERLOC |
30 | | - else |
31 | | - VERNPM=$(echo $VERNPMRAW | cut -d'-' -f1) |
32 | | - BUILD_VERSION=$(echo $VERNPMRAW | awk -F '[.-]' '{print $5+1}') |
33 | | - VEROUT=$(printf "$VERNPM\n$VERLOC\n" | sort -V -r | awk 'NR==1 {print; exit}') |
34 | | - fi |
35 | | - jq -r '.version = "'${VEROUT}'-build.'$BUILD_VERSION'"' package.json > /tmp/package.json && mv /tmp/package.json ./package.json |
36 | | - working-directory: ./dist |
37 | | - |
38 | | - - run: npm publish --tag next |
39 | | - env: |
40 | | - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
41 | | - working-directory: ./dist |
| 31 | + - name: Push Docker image |
| 32 | + run: | |
| 33 | + docker push ${{ steps.meta.outputs.image_name }}:demo |
0 commit comments