|
| 1 | +name: Release Extension on Version Change |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + - main |
| 8 | + |
| 9 | +jobs: |
| 10 | + release: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Checkout code |
| 14 | + uses: actions/checkout@v4 |
| 15 | + |
| 16 | + - name: Set up Node.js |
| 17 | + uses: actions/setup-node@v4 |
| 18 | + with: |
| 19 | + node-version: '20' |
| 20 | + |
| 21 | + - name: Get current and previous manifest.json |
| 22 | + id: manifest |
| 23 | + run: | |
| 24 | + git fetch origin ${{ github.event.before }} |
| 25 | + cp manifest.json manifest.current.json |
| 26 | + git checkout ${{ github.event.before }} -- manifest.json || echo "No previous manifest.json" |
| 27 | + cp manifest.json manifest.prev.json || echo "No previous manifest.json" |
| 28 | + git checkout ${{ github.sha }} -- manifest.json |
| 29 | +
|
| 30 | + - name: Extract versions |
| 31 | + id: versions |
| 32 | + run: | |
| 33 | + CURR_VER=$(jq -r .version manifest.current.json) |
| 34 | + PREV_VER=$(jq -r .version manifest.prev.json 2>/dev/null || echo "none") |
| 35 | + echo "current=$CURR_VER" >> $GITHUB_OUTPUT |
| 36 | + echo "previous=$PREV_VER" >> $GITHUB_OUTPUT |
| 37 | +
|
| 38 | + - name: Check if version changed |
| 39 | + id: check_version |
| 40 | + run: | |
| 41 | + if [ "${{ steps.versions.outputs.current }}" != "${{ steps.versions.outputs.previous }}" ]; then |
| 42 | + echo "changed=true" >> $GITHUB_OUTPUT |
| 43 | + else |
| 44 | + echo "changed=false" >> $GITHUB_OUTPUT |
| 45 | + fi |
| 46 | +
|
| 47 | + - name: Zip Extension Files |
| 48 | + run: | |
| 49 | + rm -f keepcode.zip |
| 50 | + zip -r keepcode.zip . \ |
| 51 | + -x "assets/*" \ |
| 52 | + -x "*.md" \ |
| 53 | + -x "assets" \ |
| 54 | + -x "assets/screenshots/*" \ |
| 55 | + -x ".git/*" \ |
| 56 | + -x ".github/*" \ |
| 57 | + -x "keepcode.zip" |
| 58 | +
|
| 59 | + - name: Create Release |
| 60 | + if: steps.check_version.outputs.changed == 'true' |
| 61 | + uses: softprops/action-gh-release@v2 |
| 62 | + with: |
| 63 | + tag_name: v${{ steps.versions.outputs.current }} |
| 64 | + name: Release v${{ steps.versions.outputs.current }} |
| 65 | + body: | |
| 66 | + Automated release for version ${{ steps.versions.outputs.current }}. |
| 67 | + files: keepcode.zip |
| 68 | + env: |
| 69 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments