From a95d61133bb6326fdb8c9e4219ec1f6c163bee4c Mon Sep 17 00:00:00 2001 From: ZackaryW <36378555+ZackaryW@users.noreply.github.com> Date: Fri, 6 Sep 2024 23:05:13 -0700 Subject: [PATCH 1/3] ci: adds auto release --- .github/workflows/release.yml | 90 +++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ab12bb4 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,90 @@ +name: Release Package + +on: + push: + branches: + - main + - master + paths: + - package.json + pull_request: + branches: + - main + - master + paths: + - package.json + workflow_dispatch: + inputs: + version: + description: 'Version to release' + required: true + type: string + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '16' # Use your preferred version + + - name: Install dependencies + run: npm install + + - name: Get version from package.json + id: get_version + run: | + VERSION=$(cat package.json | jq -r '.version') + echo "VERSION=$VERSION" >> $GITHUB_ENV + + - name: Set GitHub Token + run: echo "GH_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV + + - name: Check if version exists in releases + id: version_check + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + VERSION_EXISTS=$(gh release list | grep -w "$VERSION" || true) + if [ -n "$VERSION_EXISTS" ]; then + echo "Version $VERSION already exists. Aborting." + exit 0 + fi + + - name: Update version in package.json (Manual Trigger) + if: github.event_name == 'workflow_dispatch' + run: | + VERSION=${{ github.event.inputs.version }} + npm version $VERSION --no-git-tag-version + echo "Updated package.json to version $VERSION" + + - name: Update version in manifest.json + run: | + VERSION=$(cat package.json | jq -r '.version') + jq --arg v "$VERSION" '.version = $v' manifest.json > manifest_tmp.json + mv manifest_tmp.json manifest.json + + - name: Build the project + run: npm run build + + - name: Create Release Directory + run: | + mkdir -p output + cp manifest.json output/ + if [ -f styles.css ]; then + cp styles.css output/ + if [ -f main.js ]; then + cp main.js output/ + fi + + - name: Create GitHub Release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + VERSION=$(cat package.json | jq -r '.version') + gh release create "$VERSION" ./output/* --title "v$VERSION" --notes "Release $VERSION" From 9911d19dfd09ea62c817bd1bd507933e6a52848b Mon Sep 17 00:00:00 2001 From: ZackaryW <36378555+ZackaryW@users.noreply.github.com> Date: Sat, 7 Sep 2024 12:51:35 -0700 Subject: [PATCH 2/3] fix: missing fi --- .github/workflows/release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ab12bb4..24ee74f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -78,6 +78,7 @@ jobs: cp manifest.json output/ if [ -f styles.css ]; then cp styles.css output/ + fi if [ -f main.js ]; then cp main.js output/ fi From c0c8a4c85c6ee3c1937defe0b29068767ebb9a53 Mon Sep 17 00:00:00 2001 From: ZackaryW <36378555+ZackaryW@users.noreply.github.com> Date: Mon, 9 Sep 2024 09:38:03 -0700 Subject: [PATCH 3/3] ci: add ability to push changes --- .github/workflows/release.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 24ee74f..9291c48 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,6 +22,7 @@ on: jobs: release: + if: github.actor != 'github-actions[bot]' runs-on: ubuntu-latest steps: @@ -69,6 +70,15 @@ jobs: jq --arg v "$VERSION" '.version = $v' manifest.json > manifest_tmp.json mv manifest_tmp.json manifest.json + + - name: Commit and push changes + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add package.json manifest.json + git commit -m "Bump version to $VERSION" + git push + - name: Build the project run: npm run build