diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9af6ac0..677474a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,7 +17,8 @@ env: FORCE_COLOR: 1 jobs: - build_and_push: + release: + if: startsWith(github.ref, 'refs/tags/v') runs-on: ubuntu-latest steps: - name: Set up QEMU for multiplatform builds @@ -50,10 +51,12 @@ jobs: - name: Build and push docker image run: | - earthly --ci --push +multiplatformBuild \ + earthly --ci --push +build-and-release \ + --GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} \ --DOCKERHUB_REPO=$GITHUB_REPO \ --DOCKERHUB_USERNAME=$DOCKERHUB_USERNAME \ - --DOCKERHUB_ACCESS_TOKEN=$DOCKERHUB_TOKEN + --DOCKERHUB_ACCESS_TOKEN=$DOCKERHUB_TOKEN \ + --RELEASE_VERSION=${GITHUB_REF:10} - name: Docker Hub Description uses: peter-evans/dockerhub-description@v3 @@ -62,28 +65,3 @@ jobs: password: ${{ env.DOCKERHUB_TOKEN }} repository: ${{ env.GITHUB_REPO }} short-description: ${{ github.event.repository.description }} - - release: - permissions: - contents: write - # needs: test - if: startsWith(github.ref, 'refs/tags/v') - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Put back the git branch into git (Earthly uses it for tagging) - run: | - branch="" - if [ -n "$GITHUB_HEAD_REF" ]; then - branch="$GITHUB_HEAD_REF" - else - branch="${GITHUB_REF##*/}" - fi - git checkout -b "$branch" || true - - name: Download Earthly - run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/download/v0.7.8/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'" - - name: Build and create release - run: | - earthly --ci +release \ - --RELEASE_VERSION=${GITHUB_REF:10} \ - --GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} diff --git a/Earthfile b/Earthfile index 3745a45..0196584 100644 --- a/Earthfile +++ b/Earthfile @@ -3,16 +3,16 @@ VERSION 0.7 ARG --global DOCKERHUB_REPO=cyxou/firefly-iii-telegram-bot ARG --global DOCKERHUB_USERNAME=cyxou ARG --global DOCKERHUB_ACCESS_TOKEN +ARG --global GITHUB_TOKEN +ARG --global RELEASE_VERSION=latest FROM node:20-bullseye -WORKDIR /home/node/app -COPY package.json . -RUN node -e "console.log(require('./package.json').version)" > ./version.txt -ARG VERSION=$(cat ./version.txt) +WORKDIR /home/node/app -multiplatformBuild: +build-and-release: BUILD --platform=linux/amd64 --platform=linux/arm +buildImage + BUILD +release validatePR: BUILD +runTests @@ -44,14 +44,12 @@ runTests: RUN echo "😞 No tests yet..." buildImage: - ARG TAG=${VERSION} - COPY +buildDist/dist ./dist COPY +deps/node_modules_prod ./node_modules CMD ["dist/index.js"] - SAVE IMAGE --push $DOCKERHUB_REPO:$TAG + SAVE IMAGE --push $DOCKERHUB_REPO:$RELEASE_VERSION SAVE IMAGE --push $DOCKERHUB_REPO:latest checkIfTagExist: @@ -71,7 +69,7 @@ checkIfTagExist: release: ARG --required GITHUB_TOKEN ARG --required RELEASE_VERSION - ARG OUT_BASE="./dist" + ENV OUT_BASE="./dist" ENV REPO="cyxou/firefly-iii-telegram-bot" COPY +buildDist/dist ./dist @@ -81,20 +79,13 @@ release: && chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ && apt-get update && apt-get install gh jq -y \ - && gh --version - - # Generate release notes - RUN gh api -X POST 'repos/${REPO}/releases/generate-notes' \ + && gh --version \ + && gh api -X POST 'repos/${REPO}/releases/generate-notes' \ -F commitish=${RELEASE_VERSION} \ -F tag_name=${RELEASE_VERSION} \ - > tmp-release-notes.json - - # Gzip the bins - RUN tar -czvf "firefly-iii-telegram-bot.tar.gz" ${OUT_BASE} - - # Create release - RUN ls -al - RUN jq -r .body tmp-release-notes.json > tmp-release-notes.md \ + > tmp-release-notes.json \ + && tar -czvf "firefly-iii-telegram-bot.tar.gz" ${OUT_BASE} \ + && jq -r .body tmp-release-notes.json > tmp-release-notes.md \ && gh release create ${RELEASE_VERSION} \ --repo ${REPO} \ --title "$(jq -r .name tmp-release-notes.json)" \