From 31971c0c51a252fe547624ea49c3ed4f595c3051 Mon Sep 17 00:00:00 2001 From: Torsten Curdt Date: Mon, 6 Sep 2021 07:34:13 +0200 Subject: [PATCH] publish master and releases (#1126) * no artifacts, not required * renamed * cleanup and comments * pass build args * two-step docker build * renamed to as we might push to any docker repo * rename and cleanup * added some docs and expectation about the CI/CD and release information * combined all workflows into steps --- .github/workflows/ci.yml | 62 +++++++++++++++++++++++-- .github/workflows/release-dockerhub.yml | 44 ------------------ .github/workflows/release-npm.yml | 22 --------- RELEASE.md | 25 ++++++++++ 4 files changed, 82 insertions(+), 71 deletions(-) delete mode 100644 .github/workflows/release-dockerhub.yml delete mode 100644 .github/workflows/release-npm.yml create mode 100644 RELEASE.md diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f3b586f2..c17f2851 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,9 +4,6 @@ on: - push - pull_request -env: - project: 'gun' - jobs: test: @@ -48,7 +45,7 @@ jobs: - name: Test run: npm test - # only create a release for tags named 'v*' + # create github release release: if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') needs: [ test ] @@ -58,5 +55,60 @@ jobs: # create github release (which triggers the release workflows) - name: Release uses: softprops/action-gh-release@v1 + # env: + # GITHUB_TOKEN: ${{ secrets.PAT }} + + # publish latest master or release to dockerhub + dockerhub: + if: github.event_name == 'push' + needs: [ test ] + runs-on: ubuntu-latest + env: + image: ${{ secrets.DOCKERHUB_USERNAME }}/gun + steps: + + - name: Checkout + uses: actions/checkout@v2 + + - name: Login env: - GITHUB_TOKEN: ${{ secrets.PAT }} + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + run: echo -n ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin + + - name: Build + run: | + echo "SHA=$GITHUB_SHA" + docker build --build-arg SHA=$GITHUB_SHA \ + BUILD_DATE=$(date +'%Y-%m-%dT%H:%M:%S') \ + VCS_REF=${GITHUB_REF} \ + VCS_URL=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} \ + VERSION=${GITHUB_REF##*/} \ + SHA=$GITHUB_SHA \ + --label "SHA=$GITHUB_SHA" \ + --tag ${{ env.image }}:${GITHUB_REF##*/} \ + --tag ${{ env.image }}:latest \ + . + + - name: Push + run: docker push ${{ env.image }} + + + # publish release to npm + npm: + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + needs: [ test ] + # needs: [ release ] + runs-on: ubuntu-latest + steps: + + - name: Checkout + uses: actions/checkout@v2 + + - name: Publish + env: + NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} + run: | + npm config set //registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN + npm install + npm publish --access=public diff --git a/.github/workflows/release-dockerhub.yml b/.github/workflows/release-dockerhub.yml deleted file mode 100644 index 39dd96d8..00000000 --- a/.github/workflows/release-dockerhub.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: dockerhub - -on: - release: - types: [ published ] - -env: - project: 'gun' - -jobs: - - dockerhub: - runs-on: ubuntu-latest - steps: - - - name: Checkout - uses: actions/checkout@v2 - - - name: Build - run: | - docker build -t ${{ env.project }} . - - - name: Login - env: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} - run: echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin - - - name: Build - run: | - echo "SHA=$GITHUB_SHA" - docker build --build-arg \ - SHA=$GITHUB_SHA \ - BUILD_DATE=$(date +'%Y-%m-%d') \ - VCS_REF=${GITHUB_REF/refs\/tags\/v/} \ - VCS_URL=$GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} \ - VERSION=${GITHUB_REF/refs\/tags\/v/} \ - --label "sha=$GITHUB_SHA" \ - --tag ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.project }}:${GITHUB_REF/refs\/tags\/v/} \ - --tag ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.project }}:latest \ - . - - - name: Push - run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.project }} diff --git a/.github/workflows/release-npm.yml b/.github/workflows/release-npm.yml deleted file mode 100644 index d66cbed6..00000000 --- a/.github/workflows/release-npm.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: npm - -on: - release: - types: [ published ] - -jobs: - - npm: - runs-on: ubuntu-latest - steps: - - - name: Checkout - uses: actions/checkout@v2 - - - name: Publish - env: - NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} - run: | - npm config set //registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN - npm install - npm publish --access=public diff --git a/RELEASE.md b/RELEASE.md new file mode 100644 index 00000000..8fb6bc1b --- /dev/null +++ b/RELEASE.md @@ -0,0 +1,25 @@ +Every push or pull request will + + - run the tests + +Every push to master will + + - run the tests + - publish the latest docker image to dockerhub + +Creating a tag that starts with `v` will + + - create a new github release + - publish the release to npm + - publish the release to dockerhub + +Creating a release from the github web interface will + + - publish the release to npm + - publish the release to dockerhub + +Creating the release for version `0.2021.001` from the command line works as follows + + git tag v0.2021.001 + git push --tags +